From: Mike Bayer Date: Tue, 18 Jul 2017 18:58:26 +0000 (-0400) Subject: Check for non-entity when inspecting for subqueryload X-Git-Tag: rel_1_2_0b2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d41ea09a899b06feedd02864a69b8dc833f5a6b;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git 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 --- diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst index 602be13d24..9ea6adbf76 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 4b9eb3b0fd..11ebcee50b 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 7561c0f7cf..606beb5aa8 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."""