]> 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:21:05 +0000 (09:21 -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

(cherry picked from commit 24d6ea362e757c79b3bada663cf6fc9f262dae4f)

lib/sqlalchemy/orm/query.py
test/orm/test_query.py

index 75521f03d8ab6c1d1401066f21a5dddc529789b7..fd8f9d53b461e35f8c379399a02c63af03efde01 100644 (file)
@@ -2479,18 +2479,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 cb7185f30aa893cdeffbd18542515a1f12b725c1..444bd3c22c28b9532e219d8fcb211054ff5e86e6 100644 (file)
@@ -64,6 +64,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')
@@ -99,6 +100,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),
                 [