]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug in new "label resolution" feature of :ticket:`2992` where
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 21 Mar 2015 17:12:15 +0000 (13:12 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 21 Mar 2015 17:12:15 +0000 (13:12 -0400)
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.
fixes #3335

doc/build/changelog/changelog_10.rst
lib/sqlalchemy/__init__.py
lib/sqlalchemy/sql/selectable.py
test/sql/test_text.py

index eb68b43a4bfc9289ae81de09b2e3353929d03c17..9f68d05eb1edd2f45205f805689ad24b3a0a0e3c 100644 (file)
     .. 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
index 94ab772b147390870d0f2b719c88d559889b2f51..c1e84733c317a6d3983c26c4918da8e648cbf57f 100644 (file)
@@ -120,7 +120,7 @@ from .schema import (
 from .inspection import inspect
 from .engine import create_engine, engine_from_config
 
-__version__ = '1.0.0b3'
+__version__ = '1.0.0b4'
 
 
 def __go(lcls):
index 6520f08fc87ee8c9e4bca9f0c0df2f4c5466127c..b5a7489bf9aa9c3a55bead39d52ebe51e91c41cc 100644 (file)
@@ -2680,7 +2680,8 @@ class Select(HasPrefixes, HasSuffixes, GenerativeSelect):
         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
 
index c2f4d2c151a0055d3d956717e687e3fb68573f17..4483597ac017a53c09666299d432dbcab6932595 100644 (file)
@@ -574,6 +574,20 @@ class OrderByLabelResolutionTest(fixtures.TestBase, AssertsCompiledSQL):
             "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(