]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- More issues with [ticket:2932] first resolved in 0.9.2 where
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 6 Feb 2014 00:25:13 +0000 (19:25 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 6 Feb 2014 00:25:13 +0000 (19:25 -0500)
using a column key of the form ``<tablename>_<columnname>``
matching that of an aliased column in the text would still not
match at the ORM level, which is ultimately due to a core
column-matching issue.  Additional rules have been added so that the
column ``_label`` is taken into account when working with a
:class:`.TextAsFrom` construct or with literal columns.
[ticket:2932]

doc/build/changelog/changelog_09.rst
lib/sqlalchemy/sql/elements.py
test/sql/test_query.py

index d7ca44beeb6a9a0ff94322d8bc72240a5ab283a5..87f1b2494970f3734f07e264dff2f0b68d2bb38e 100644 (file)
         mappers step has occurred, e.g. it will just work without throwing
         any error.
 
+    .. change::
+        :tags: bug, orm
+        :tickets: 2932
+
+        More issues with [ticket:2932] first resolved in 0.9.2 where
+        using a column key of the form ``<tablename>_<columnname>``
+        matching that of an aliased column in the text would still not
+        match at the ORM level, which is ultimately due to a core
+        column-matching issue.  Additional rules have been added so that the
+        column ``_label`` is taken into account when working with a
+        :class:`.TextAsFrom` construct or with literal columns.
+
 .. changelog::
     :version: 0.9.2
     :released: February 2, 2014
index cca03851f8d02c8a53e03eed342d35171dbe47f1..2846b3b51ff934b73d6e9543187ff8e6b0c394b9 100644 (file)
@@ -2927,8 +2927,8 @@ class ColumnClause(Immutable, ColumnElement):
                         other.table is None or
                         other.table._textual)
         ):
-            return super(ColumnClause, self).\
-                    _compare_name_for_result(other)
+            return (hasattr(other, 'name') and self.name == other.name) or \
+                (hasattr(other, '_label') and self._label == other._label)
         else:
             return other.proxy_set.intersection(self.proxy_set)
 
index 6e2227650105fe5c2efb55e6dadcb6486cc0f93c..c200878599dfa99f3b3d0f8e536df6c91aaf5e2a 100644 (file)
@@ -1831,6 +1831,36 @@ class KeyTargetingTest(fixtures.TablesTest):
         assert stmt.c.a in row
         assert stmt.c.b in row
 
+    def test_columnclause_schema_column_four(self):
+        keyed2 = self.tables.keyed2
+
+        # this is also addressed by [ticket:2932]
+
+        a, b = sql.column('keyed2_a'), sql.column('keyed2_b')
+        stmt = text("select a AS keyed2_a, b AS keyed2_b from keyed2").columns(a, b)
+        row = testing.db.execute(stmt).first()
+
+        assert keyed2.c.a in row
+        assert keyed2.c.b in row
+        assert a in row
+        assert b in row
+        assert stmt.c.keyed2_a in row
+        assert stmt.c.keyed2_b in row
+
+    def test_columnclause_schema_column_five(self):
+        keyed2 = self.tables.keyed2
+
+        # this is also addressed by [ticket:2932]
+
+        stmt = text("select a AS keyed2_a, b AS keyed2_b from keyed2").columns(
+                            keyed2_a=CHAR, keyed2_b=CHAR)
+        row = testing.db.execute(stmt).first()
+
+        assert keyed2.c.a in row
+        assert keyed2.c.b in row
+        assert stmt.c.keyed2_a in row
+        assert stmt.c.keyed2_b in row
+
 
 
 class LimitTest(fixtures.TestBase):