]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Ensure we have states to load when doing poly post load
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 23 Feb 2018 18:55:17 +0000 (13:55 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 23 Feb 2018 19:19:13 +0000 (14:19 -0500)
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
doc/build/changelog/unreleased_12/4199.rst [new file with mode: 0644]
lib/sqlalchemy/orm/loading.py
test/orm/inheritance/test_poly_loading.py

diff --git a/doc/build/changelog/unreleased_12/4199.rst b/doc/build/changelog/unreleased_12/4199.rst
new file mode 100644 (file)
index 0000000..2852839
--- /dev/null
@@ -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".
index 2544f7f9966ce81c27c521c09d4404dec937fda1..2628093e01c02024c2bb2ba11485407b734c8d7e 100644 (file)
@@ -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
index f6046b3b2153c13fd841d02d273c45de56e20112..b07b498a67ed4c77d92080ada588f5582bab8704 100644 (file)
@@ -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()