From: Mike Bayer Date: Fri, 23 Feb 2018 18:55:17 +0000 (-0500) Subject: Ensure we have states to load when doing poly post load X-Git-Tag: rel_1_2_5~13^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3859256312c8114ca7104f59c90f68623893a630;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Ensure we have states to load when doing poly post load Fixed bug in new "polymorphic selectin" loading when a selection of polymorphic objects were to be partially loaded from a relationship lazy loader, leading to an "empty IN" condition within the load that raises an error for the "inline" form of "IN". Change-Id: I721cf5fdf0b9fd2289067d5d2c6bc87fb2436f07 Fixes: #4199 --- diff --git a/doc/build/changelog/unreleased_12/4199.rst b/doc/build/changelog/unreleased_12/4199.rst new file mode 100644 index 0000000000..2852839ef7 --- /dev/null +++ b/doc/build/changelog/unreleased_12/4199.rst @@ -0,0 +1,8 @@ +.. change:: + :tags: bug, orm + :tickets: 4199 + + Fixed bug in new "polymorphic selectin" loading when a selection of + polymorphic objects were to be partially loaded from a relationship + lazy loader, leading to an "empty IN" condition within the load that + raises an error for the "inline" form of "IN". diff --git a/lib/sqlalchemy/orm/loading.py b/lib/sqlalchemy/orm/loading.py index 2544f7f996..2628093e01 100644 --- a/lib/sqlalchemy/orm/loading.py +++ b/lib/sqlalchemy/orm/loading.py @@ -755,8 +755,8 @@ class PostLoad(object): in self.states.items() if state.manager.mapper.isa(limit_to_mapper) ] - loader( - context, path, states, self.load_keys, *arg, **kw) + if states: + loader(context, path, states, self.load_keys, *arg, **kw) self.states.clear() @classmethod diff --git a/test/orm/inheritance/test_poly_loading.py b/test/orm/inheritance/test_poly_loading.py index f6046b3b21..b07b498a67 100644 --- a/test/orm/inheritance/test_poly_loading.py +++ b/test/orm/inheritance/test_poly_loading.py @@ -468,3 +468,32 @@ class TestGeometries(GeometryFixtureBase): result, [d(d_data="d1"), e(e_data="e1")] ) + + def test_partial_load_no_invoke_eagers(self): + # test issue #4199 + + self._fixture_from_geometry({ + "a": { + "subclasses": { + "a1": {"polymorphic_load": "selectin"}, + "a2": {"polymorphic_load": "selectin"} + } + } + }) + + a, a1, a2 = self.classes("a", "a1", "a2") + sess = Session() + + a1_obj = a1() + a2_obj = a2() + sess.add_all([a1_obj, a2_obj]) + + del a2_obj + sess.flush() + sess.expire_all() + + # _with_invoke_all_eagers(False), used by the lazy loader + # strategy, will cause one less state to be present such that + # the poly loader won't locate a state limited to the "a1" mapper, + # needs to test that it has states + sess.query(a)._with_invoke_all_eagers(False).all()