]> 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:02:39 +0000 (15:02 -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
doc/build/changelog/changelog_11.rst
lib/sqlalchemy/orm/strategies.py
test/orm/test_subquery_relations.py

index 602be13d24eaffd5efa87645ad6d9f48b314fac5..9ea6adbf767f8a8677e0105c3c54735417e03740 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 4b9eb3b0fd7736e266d561a8ab2b02d4063d8fc4..11ebcee50bb50f3191859c3e7f7d4375613c2e77 100644 (file)
@@ -985,6 +985,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 7561c0f7cfba3299daa038c11f8363ff926382c5..606beb5aa8434e20931b02754b09996f142a16cf 100644 (file)
@@ -540,6 +540,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."""