[Sqlalchemy-tickets] Issue #3967: subquery eager loading doesn't use join_depth correctly (zzzeek/s
Brought to you by:
zzzeek
From: Michael B. <iss...@bi...> - 2017-04-17 15:52:55
|
New issue 3967: subquery eager loading doesn't use join_depth correctly https://bitbucket.org/zzzeek/sqlalchemy/issues/3967/subquery-eager-loading-doesnt-use Michael Bayer: the join_depth parameter w/ subquery eager loading causes it to just load infinitely as long as there are objects ``` #!diff diff --git a/test/orm/test_subquery_relations.py b/test/orm/test_subquery_relations.py index 1396281..2b8068d 100644 --- a/test/orm/test_subquery_relations.py +++ b/test/orm/test_subquery_relations.py @@ -517,6 +517,29 @@ class EagerTest(_fixtures.FixtureTest, testing.AssertsCompiledSQL): eq_(self.static.user_address_result, sess.query(User).order_by(User.id).all()) + def test_cyclical_explicit_join_depth(self): + """A circular eager relationship breaks the cycle with a lazy loader""" + + 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', join_depth=1, + backref=sa.orm.backref( + 'user', lazy='subquery', join_depth=1), + order_by=Address.id) + )) + is_(sa.orm.class_mapper(User).get_property('addresses').lazy, + 'subquery') + is_(sa.orm.class_mapper(Address).get_property('user').lazy, 'subquery') + + sess = create_session() + eq_(self.static.user_address_result, + sess.query(User).order_by(User.id).all()) + def test_double(self): """Eager loading with two relationships simultaneously, from the same table, using aliases.""" ``` will cause a crash. similarly, the test "test_lazy_fallback_doesnt_affect_eager" doesn't make sense; the subquery loads are emitted for all levels deep when the join_depth=1. it should only eagerly load one level deep. |