[Sqlalchemy-tickets] Issue #3824: switch off of other-side joinedload from m2o will fail if source
Brought to you by:
zzzeek
From: Michael B. <iss...@bi...> - 2016-10-14 20:54:44
|
New issue 3824: switch off of other-side joinedload from m2o will fail if source object has options already https://bitbucket.org/zzzeek/sqlalchemy/issues/3824/switch-off-of-other-side-joinedload-from Michael Bayer: this is from #1495, adding a bogus MapperOption that propagates to a lazyload causes the path arithmetic to fail: ``` #!diff --- a/test/orm/test_eager_relations.py +++ b/test/orm/test_eager_relations.py @@ -898,6 +898,44 @@ class EagerTest(_fixtures.FixtureTest, testing.AssertsCompiledSQL): {'param_1': 8}) ) + def test_useget_cancels_eager_propagated_present(self): + """test that a one to many lazyload cancels the unnecessary + eager many-to-one join on the other side, even when a propagated + option is present.""" + + users, Address, addresses, User = ( + self.tables.users, + self.classes.Address, + self.tables.addresses, + self.classes.User) + + mapper(User, users) + mapper(Address, addresses, properties={ + 'user': relationship(User, lazy='joined', backref='addresses') + }) + + from sqlalchemy.orm.interfaces import MapperOption + + class MyBogusOption(MapperOption): + propagate_to_loaders = True + + sess = create_session() + u1 = sess.query(User).options(MyBogusOption()).filter(User.id == 8).one() + + + def go(): + eq_(u1.addresses[0].user, u1) + self.assert_sql_execution( + testing.db, go, + CompiledSQL( + "SELECT addresses.id AS addresses_id, addresses.user_id AS " + "addresses_user_id, addresses.email_address AS " + "addresses_email_address FROM addresses WHERE :param_1 = " + "addresses.user_id", + {'param_1': 8}) + ) + + def test_manytoone_limit(self): """test that the subquery wrapping only occurs with limit/offset and m2m or o2m joins present.""" ``` gerrit forthcoming |