From: Mike Bayer Date: Thu, 30 Apr 2015 16:53:27 +0000 (-0400) Subject: - Fixed regression from as yet unreleased 0.9.10 where the new addition X-Git-Tag: rel_1_0_3~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=20e3df602846bb1d8940b5138f21ef203c99bade;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Fixed regression from as yet unreleased 0.9.10 where the new addition of ``entity`` to the :attr:`.Query.column_descriptions` accessor would fail if the target entity was produced from a core selectable such as a :class:`.Table` or :class:`.CTE` object. fixes #3403 references #3320 --- diff --git a/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst index 2f2f592635..778881b909 100644 --- a/doc/build/changelog/changelog_09.rst +++ b/doc/build/changelog/changelog_09.rst @@ -110,6 +110,9 @@ Compared to the existing entry for ``"type"``, it will always be a mapped entity, even if extracted from a column expression, or None if the given expression is a pure core expression. + See also :ticket:`3403` which repaired a regression in this feature + which was unreleased in 0.9.10 but was released in the 1.0 version. + .. changelog:: :version: 0.9.9 diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst index 5e32c667fb..4368916017 100644 --- a/doc/build/changelog/changelog_10.rst +++ b/doc/build/changelog/changelog_10.rst @@ -18,6 +18,15 @@ .. changelog:: :version: 1.0.3 + .. change:: + :tags: bug, orm + :tickets: 3403, 3320 + + Fixed regression from as yet unreleased 0.9.10 where the new addition + of ``entity`` to the :attr:`.Query.column_descriptions` accessor + would fail if the target entity was produced from a core selectable + such as a :class:`.Table` or :class:`.CTE` object. + .. change:: :tags: feature, sql diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index c3638f66d4..f4b04b078e 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -2577,6 +2577,7 @@ class Query(object): 'expr': ent.expr, 'entity': ent.entity_zero.entity if ent.entity_zero is not None + and not inspect(ent.entity_zero).is_selectable else None } for ent in self._entities @@ -3620,7 +3621,6 @@ class _ColumnEntity(_QueryEntity): if 'parententity' in elem._annotations and actual_froms.intersection(elem._from_objects) ]) - if self.entities: self.entity_zero = self.entities[0] elif self.namespace is not None: diff --git a/test/orm/test_query.py b/test/orm/test_query.py index 850014ab44..cb428469e7 100644 --- a/test/orm/test_query.py +++ b/test/orm/test_query.py @@ -73,6 +73,7 @@ class RowTupleTest(QueryTest): fn = func.count(User.id) name_label = User.name.label('uname') bundle = Bundle('b1', User.id, User.name) + cte = sess.query(User.id).cte() for q, asserted in [ ( sess.query(User), @@ -122,6 +123,26 @@ class RowTupleTest(QueryTest): 'expr': fn, 'entity': User}, ] ), + ( + sess.query(cte), + [ + { + 'aliased': False, + 'expr': cte.c.id, 'type': cte.c.id.type, + 'name': 'id', 'entity': None + }] + ), + ( + sess.query(users), + [ + {'aliased': False, + 'expr': users.c.id, 'type': users.c.id.type, + 'name': 'id', 'entity': None}, + {'aliased': False, + 'expr': users.c.name, 'type': users.c.name.type, + 'name': 'name', 'entity': None} + ] + ), ( sess.query(users.c.name), [{