.. include:: changelog_07.rst
:start-line: 5
+.. changelog::
+ :version: 1.0.0b4
+
+ .. change::
+ :tags: bug, sql
+ :tickets: 3335
+
+ Fixed bug in new "label resolution" feature of :ticket:`2992` where
+ the string label placed in the order_by() or group_by() of a statement
+ would place higher priority on the name as found
+ inside the FROM clause instead of a more locally available name
+ inside the columns clause.
+
.. changelog::
:version: 1.0.0b3
:released: March 20, 2015
only_froms = dict(
(c.key, c) for c in
_select_iterables(self.froms) if c._allow_label_resolve)
- with_cols.update(only_froms)
+ for key, value in only_froms.items():
+ with_cols.setdefault(key, value)
return with_cols, only_froms
"FROM mytable AS mytable_1 ORDER BY mytable_1.name"
)
+ def test_order_by_outermost_label(self):
+ # test [ticket:3335], assure that order_by("foo")
+ # catches the label named "foo" in the columns clause only,
+ # and not the label named "foo" in the FROM clause
+ s1 = select([table1.c.myid.label("foo"), table1.c.name]).alias()
+ stmt = select([s1.c.name, func.bar().label("foo")]).order_by("foo")
+
+ self.assert_compile(
+ stmt,
+ "SELECT anon_1.name, bar() AS foo FROM "
+ "(SELECT mytable.myid AS foo, mytable.name AS name "
+ "FROM mytable) AS anon_1 ORDER BY foo"
+ )
+
def test_unresolvable_warning_order_by(self):
stmt = select([table1.c.myid]).order_by('foobar')
self._test_warning(