--- /dev/null
+.. change::
+ :tags: bug, orm
+ :tickets: 10834
+
+ Fixed issue where using the :meth:`_orm.Query.enable_eagerloads` and
+ :meth:`_orm.Query.yield_per` methods at the same time, in order to disable
+ eager loading that's configured on the mapper directly, would be silently
+ ignored, leading to errors or unexpected eager population of attributes.
adapter,
populators,
):
+ if not context.compile_state.compile_options._enable_eagerloads:
+ return
+
(
effective_path,
run_loader,
execution_options,
recursion_depth,
) = self._setup_for_recursion(context, path, loadopt, self.join_depth)
+
if not run_loader:
# this will not emit SQL and will only emit for a many-to-one
# "use get" load. the "_RELATED" part means it may return
adapter,
populators,
):
+
+ if not context.compile_state.compile_options._enable_eagerloads:
+ return
+
if not self.parent.class_manager[self.key].impl.supports_population:
raise sa_exc.InvalidRequestError(
"'%s' does not support object "
if not run_loader:
return
+ if not context.compile_state.compile_options._enable_eagerloads:
+ return
+
if not self.parent.class_manager[self.key].impl.supports_population:
raise sa_exc.InvalidRequestError(
"'%s' does not support object "
)
eq_(len(q.all()), 4)
+ @testing.combinations(
+ "joined",
+ "subquery",
+ "selectin",
+ "select",
+ "immediate",
+ argnames="lazy",
+ )
+ def test_eagerload_config_disable(self, lazy):
+ self._eagerload_mappings(addresses_lazy=lazy)
+
+ User = self.classes.User
+ sess = fixture_session()
+ q = sess.query(User).enable_eagerloads(False).yield_per(1)
+ objs = q.all()
+ eq_(len(objs), 4)
+ for obj in objs:
+ assert "addresses" not in obj.__dict__
+
def test_m2o_joinedload_not_others(self):
self._eagerload_mappings(addresses_lazy="joined")
Address = self.classes.Address