diff options
-rw-r--r-- | doc/build/changelog/changelog_10.rst | 15 | ||||
-rw-r--r-- | lib/sqlalchemy/__init__.py | 2 | ||||
-rw-r--r-- | lib/sqlalchemy/orm/query.py | 17 | ||||
-rw-r--r-- | 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 08c5fe226..18347e6d0 100644 --- a/doc/build/changelog/changelog_10.rst +++ b/doc/build/changelog/changelog_10.rst @@ -16,6 +16,21 @@ :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 153b10a2b..6f7a4f723 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 f4b04b078..8421e42ac 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 cb428469e..6a1eb57b4 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') @@ -105,6 +106,24 @@ class RowTupleTest(QueryTest): ] ), ( + 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), [ { |