diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-07-18 14:58:26 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-07-18 15:02:39 -0400 |
commit | 3d41ea09a899b06feedd02864a69b8dc833f5a6b (patch) | |
tree | 1a1008d7ee2435de90b14abae32e7ade9cd8c845 | |
parent | 32f67637cd705840751bd1d8d37db87df5823a4b (diff) | |
download | sqlalchemy-3d41ea09a899b06feedd02864a69b8dc833f5a6b.tar.gz |
Check for non-entity when inspecting for subqueryload
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
-rw-r--r-- | doc/build/changelog/changelog_11.rst | 10 | ||||
-rw-r--r-- | lib/sqlalchemy/orm/strategies.py | 1 | ||||
-rw-r--r-- | test/orm/test_subquery_relations.py | 19 |
3 files changed, 30 insertions, 0 deletions
diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst index 602be13d2..9ea6adbf7 100644 --- a/doc/build/changelog/changelog_11.rst +++ b/doc/build/changelog/changelog_11.rst @@ -21,6 +21,16 @@ .. 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 diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py index 4b9eb3b0f..11ebcee50 100644 --- a/lib/sqlalchemy/orm/strategies.py +++ b/lib/sqlalchemy/orm/strategies.py @@ -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 ) diff --git a/test/orm/test_subquery_relations.py b/test/orm/test_subquery_relations.py index 7561c0f7c..606beb5aa 100644 --- a/test/orm/test_subquery_relations.py +++ b/test/orm/test_subquery_relations.py @@ -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.""" |