diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2018-02-23 13:55:17 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2018-02-23 14:19:13 -0500 |
| commit | 3859256312c8114ca7104f59c90f68623893a630 (patch) | |
| tree | 31fbe5c0a8b6e892129ac317b7240d57c82826f7 | |
| parent | f7dcac6967b3068b2dc2209cd4c6bf966206f8e9 (diff) | |
| download | sqlalchemy-3859256312c8114ca7104f59c90f68623893a630.tar.gz | |
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
| -rw-r--r-- | doc/build/changelog/unreleased_12/4199.rst | 8 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/loading.py | 4 | ||||
| -rw-r--r-- | test/orm/inheritance/test_poly_loading.py | 29 |
3 files changed, 39 insertions, 2 deletions
diff --git a/doc/build/changelog/unreleased_12/4199.rst b/doc/build/changelog/unreleased_12/4199.rst new file mode 100644 index 000000000..2852839ef --- /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 2544f7f99..2628093e0 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 f6046b3b2..b07b498a6 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() |
