- changed status to resolved
switch off of other-side joinedload from m2o will fail if source object has options already
Issue #3824
resolved
this is from #1495, adding a bogus MapperOption that propagates to a lazyload causes the path arithmetic to fail:
--- 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
Comments (1)
-
reporter - Log in to comment
Assemble "don't joinedload other side" rule using query._current_path
Discovered during testing for [ticket:3822], the rule added for [ticket:1495] will fail if the source object has propagated options set up, which add elements to query._current_path.
Fixes:
#3824Change-Id: I3d96c96fee5f9b247f739d2136d18681ac61f2fe→ <<cset ae7d2837b3c5>>