diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-02-05 19:25:13 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-02-05 19:25:13 -0500 |
commit | 5c188f6c1ce85eaace27f052bfd1a14f74f6a659 (patch) | |
tree | 0f703326bc1ee1e73d2e175b0877ba07592eb27a | |
parent | c5dccd82dabffa1b01d1e2852c96684b559528c2 (diff) | |
download | sqlalchemy-5c188f6c1ce85eaace27f052bfd1a14f74f6a659.tar.gz |
- 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.
[ticket:2932]
-rw-r--r-- | doc/build/changelog/changelog_09.rst | 12 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/elements.py | 4 | ||||
-rw-r--r-- | test/sql/test_query.py | 30 |
3 files changed, 44 insertions, 2 deletions
diff --git a/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst index d7ca44bee..87f1b2494 100644 --- a/doc/build/changelog/changelog_09.rst +++ b/doc/build/changelog/changelog_09.rst @@ -39,6 +39,18 @@ 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 diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index cca03851f..2846b3b51 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -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) diff --git a/test/sql/test_query.py b/test/sql/test_query.py index 6e2227650..c20087859 100644 --- a/test/sql/test_query.py +++ b/test/sql/test_query.py @@ -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): |