]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Check for non-entity when inspecting for subqueryload
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 18 Jul 2017 18:58:26 +0000 (14:58 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 18 Jul 2017 19:04:10 +0000 (15:04 -0400)
Fixed issue where adding additional non-entity columns to
a query that includes an entity with subqueryload relationships
would fail, due to an inspection added in 1.1.11 as a result of
:ticket:`4011`.

Change-Id: I8ef082be649125bdc07b428cb9b0a77a65d73671
Fixes: #4033
(cherry picked from commit 3d41ea09a899b06feedd02864a69b8dc833f5a6b)

doc/build/changelog/changelog_11.rst
lib/sqlalchemy/orm/strategies.py
test/orm/test_subquery_relations.py

index 14606f86cfc70e9755be51d3c0e45f6eeac8d706..c229ad9aeae4f36bf7c9f5941601fa1dfe26d06b 100644 (file)
 .. changelog::
     :version: 1.1.12
 
+    .. change:: 4033
+        :tags: bug, orm
+        :tickets: 4033
+        :versions: 1.2.0b2
+
+        Fixed regression from 1.1.11 where adding additional non-entity
+        columns to a query that includes an entity with subqueryload
+        relationships would fail, due to an inspection added in 1.1.11 as a
+        result of :ticket:`4011`.
+
     .. change:: cache_order_sequence
         :tags: feature, oracle, posgresql
         :versions: 1.2.0b1
index cb9e54da461c8265970e1b7072605c754f672433..d35b956875cfde9e0c5fb73b4cb7d91ed889dbec 100644 (file)
@@ -857,6 +857,7 @@ class SubqueryLoader(AbstractRelationshipLoader):
             q._set_select_from(
                 list(set([
                     ent['entity'] for ent in orig_query.column_descriptions
+                    if ent['entity'] is not None
                 ])),
                 False
             )
index eb1380072eec1d5d07826628c4e4f10b7f11b3f5..7d391b8d3005f8e63c80c170c6539aa34d8f8a2e 100644 (file)
@@ -517,6 +517,25 @@ class EagerTest(_fixtures.FixtureTest, testing.AssertsCompiledSQL):
         eq_(self.static.user_address_result,
             sess.query(User).order_by(User.id).all())
 
+    def test_add_arbitrary_exprs(self):
+        Address, addresses, users, User = (self.classes.Address,
+                                           self.tables.addresses,
+                                           self.tables.users,
+                                           self.classes.User)
+
+        mapper(Address, addresses)
+        mapper(User, users, properties=dict(
+            addresses=relationship(Address, lazy='subquery')
+        ))
+
+        sess = create_session()
+
+        self.assert_compile(
+            sess.query(User, '1'),
+            "SELECT users.id AS users_id, users.name AS users_name, "
+            "1 FROM users"
+        )
+
     def test_double(self):
         """Eager loading with two relationships simultaneously,
             from the same table, using aliases."""