From 24d6ea362e757c79b3bada663cf6fc9f262dae4f Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 1 May 2015 09:20:10 -0400 Subject: [PATCH] - Repaired / added to tests yet more expressions that were reported as failing with the new 'entity' key value added to :attr:`.Query.column_descriptions`, the logic to discover the "from" clause is again reworked to accommodate columns from aliased classes, as well as to report the correct value for the "aliased" flag in these cases. fixes #3409 --- doc/build/changelog/changelog_10.rst | 15 +++++++++++++++ lib/sqlalchemy/__init__.py | 2 +- lib/sqlalchemy/orm/query.py | 17 +++++++++++++---- test/orm/test_query.py | 19 +++++++++++++++++++ 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst index 08c5fe2262..18347e6d09 100644 --- a/doc/build/changelog/changelog_10.rst +++ b/doc/build/changelog/changelog_10.rst @@ -15,6 +15,21 @@ .. include:: changelog_07.rst :start-line: 5 +.. changelog:: + :version: 1.0.4 + + .. change:: + :tags: bug, orm + :tickets: 3409, 3320 + + Repaired / added to tests yet more expressions that were reported + as failing with the new 'entity' key value added to + :attr:`.Query.column_descriptions`, the logic to discover the "from" + clause is again reworked to accommodate columns from aliased classes, + as well as to report the correct value for the "aliased" flag in these + cases. + + .. changelog:: :version: 1.0.3 :released: April 30, 2015 diff --git a/lib/sqlalchemy/__init__.py b/lib/sqlalchemy/__init__.py index 153b10a2bf..6f7a4f7235 100644 --- a/lib/sqlalchemy/__init__.py +++ b/lib/sqlalchemy/__init__.py @@ -120,7 +120,7 @@ from .schema import ( from .inspection import inspect from .engine import create_engine, engine_from_config -__version__ = '1.0.3' +__version__ = '1.0.4' def __go(lcls): diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index f4b04b078e..8421e42acc 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -2569,18 +2569,27 @@ class Query(object): ] """ + return [ { 'name': ent._label_name, 'type': ent.type, - 'aliased': getattr(ent, 'is_aliased_class', False), + 'aliased': getattr(insp_ent, 'is_aliased_class', False), 'expr': ent.expr, 'entity': - ent.entity_zero.entity if ent.entity_zero is not None - and not inspect(ent.entity_zero).is_selectable + getattr(insp_ent, "entity", None) + if ent.entity_zero is not None + and not insp_ent.is_clause_element else None } - for ent in self._entities + for ent, insp_ent in [ + ( + _ent, + (inspect(_ent.entity_zero) + if _ent.entity_zero is not None else None) + ) + for _ent in self._entities + ] ] def instances(self, cursor, __context=None): diff --git a/test/orm/test_query.py b/test/orm/test_query.py index cb428469e7..6a1eb57b48 100644 --- a/test/orm/test_query.py +++ b/test/orm/test_query.py @@ -69,6 +69,7 @@ class RowTupleTest(QueryTest): mapper(Address, addresses) sess = create_session() user_alias = aliased(User) + user_alias_id_label = user_alias.id.label('foo') address_alias = aliased(Address, name='aalias') fn = func.count(User.id) name_label = User.name.label('uname') @@ -104,6 +105,24 @@ class RowTupleTest(QueryTest): 'expr': user_alias, 'entity': user_alias} ] ), + ( + sess.query(user_alias.id), + [ + { + 'name': 'id', 'type': users.c.id.type, + 'aliased': True, 'expr': user_alias.id, + 'entity': user_alias}, + ] + ), + ( + sess.query(user_alias_id_label), + [ + { + 'name': 'foo', 'type': users.c.id.type, + 'aliased': True, 'expr': user_alias_id_label, + 'entity': user_alias}, + ] + ), ( sess.query(address_alias), [ -- 2.47.3