]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Repaired / added to tests yet more expressions that were reported
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 1 May 2015 13:20:10 +0000 (09:20 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 1 May 2015 13:20:10 +0000 (09:20 -0400)
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
lib/sqlalchemy/__init__.py
lib/sqlalchemy/orm/query.py
test/orm/test_query.py

index 08c5fe2262c4336518ea8f23374da1607c8ec37a..18347e6d0977bf83af87320e474a60f7c4f012d9 100644 (file)
     .. 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
index 153b10a2bfd49f33347a766110b24f636597e1db..6f7a4f7235ccd55faa3ef95c7505000c81b36478 100644 (file)
@@ -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):
index f4b04b078ea6d8b7b7f550f5106f4a08ec87b35a..8421e42accb2d916b82b9bee8f371da9a91fa88d 100644 (file)
@@ -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):
index cb428469e7ca2e1f01cd324b64872bdb6bee8439..6a1eb57b486e0516a434c1f84c2af9683e4f9ad4 100644 (file)
@@ -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),
                 [