From: Carson Ip Date: Fri, 3 Jan 2020 22:09:20 +0000 (-0500) Subject: Fix QueryContext ref cycle on joinedload X-Git-Tag: rel_1_3_13~12^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=722807c84f107a26569956cbda3eaa4d9a783f7c;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix QueryContext ref cycle on joinedload Avoid storing a reference to itself when dealing with create_eager_joins. Also fix a cheating test. Fixes: #5071 Closes: #5072 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5072 Pull-request-sha: 75ebaf7c91e96d7567eb5760be713dc134c58763 Change-Id: I511ddc0979b46f7928217347199eca4b1d0b4a49 (cherry picked from commit 5ecb7732fb62d80adb4434bdd0e606e43aa14a98) --- diff --git a/doc/build/changelog/unreleased_13/5056.rst b/doc/build/changelog/unreleased_13/5056.rst index 217044c185..950cce3c20 100644 --- a/doc/build/changelog/unreleased_13/5056.rst +++ b/doc/build/changelog/unreleased_13/5056.rst @@ -1,6 +1,6 @@ .. change:: :tags: bug, orm, engine - :tickets: 5056, 5050 + :tickets: 5056, 5050, 5071 Added test support and repaired a wide variety of unnecessary reference cycles created for short-lived objects, mostly in the area of ORM queries. diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index e1a873b570..051a368f43 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -3911,7 +3911,7 @@ class Query(object): for rec in context.create_eager_joins: strategy = rec[0] - strategy(*rec[1:]) + strategy(context, *rec[1:]) if context.from_clause: # "load from explicit FROMs" mode, diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py index e234596f6f..4bd74988a5 100644 --- a/lib/sqlalchemy/orm/strategies.py +++ b/lib/sqlalchemy/orm/strategies.py @@ -1707,7 +1707,6 @@ class JoinedLoader(AbstractRelationshipLoader): context.create_eager_joins.append( ( self._create_eager_join, - context, entity, path, adapter, diff --git a/test/aaa_profiling/test_memusage.py b/test/aaa_profiling/test_memusage.py index be825151d5..0b407c1169 100644 --- a/test/aaa_profiling/test_memusage.py +++ b/test/aaa_profiling/test_memusage.py @@ -1208,6 +1208,21 @@ class CycleTest(_fixtures.FixtureTest): go() + def test_query_joinedload(self): + User, Address = self.classes("User", "Address") + + s = Session() + + def generate(): + s.query(User).options(joinedload(User.addresses)).all() + + # cycles here are due to ClauseElement._cloned_set and Load.context + @assert_cycles(28) + def go(): + generate() + + go() + def test_plain_join(self): users, addresses = self.tables("users", "addresses")