--- /dev/null
+.. change::
+ :tags: bug, orm
+ :tickets: 5737
+ :versions: 1.4.0b2
+
+ Fixed bug involving the ``restore_load_context`` option of ORM events such
+ as :meth:`_orm.InstanceEvents.load` such that the flag would not be carried
+ along to subclasses which were mapped after the event handler were first
+ established.
+
+
collection = target.all_holds[target.class_] = {}
event.registry._stored_in_collection(event_key, target)
- collection[event_key._key] = (event_key, raw, propagate, retval)
+ collection[event_key._key] = (
+ event_key,
+ raw,
+ propagate,
+ retval,
+ kw,
+ )
if propagate:
stack = list(target.class_.__subclasses__())
for subclass in class_.__mro__:
if subclass in cls.all_holds:
collection = cls.all_holds[subclass]
- for event_key, raw, propagate, retval in collection.values():
+ for (
+ event_key,
+ raw,
+ propagate,
+ retval,
+ kw,
+ ) in collection.values():
if propagate or subclass is class_:
# since we can't be sure in what order different
# classes in a hierarchy are triggered with
# assignment, instead of using the generic propagate
# flag.
event_key.with_dispatch_target(subject).listen(
- raw=raw, propagate=False, retval=retval
+ raw=raw, propagate=False, retval=retval, **kw
)
s.query(A).all()
s.close()
+ @testing.combinations(
+ ("load", lambda instance, context: instance.unloaded),
+ (
+ "refresh",
+ lambda instance, context, attrs: instance.unloaded,
+ ),
+ )
+ def test_flag_resolves_existing_for_subclass(self, event_name, fn):
+ Base = declarative_base()
+
+ event.listen(
+ Base, event_name, fn, propagate=True, restore_load_context=True
+ )
+
+ class A(Base):
+ __tablename__ = "a"
+ id = Column(Integer, primary_key=True)
+ unloaded = deferred(Column(String(50)))
+
+ s = Session(testing.db)
+
+ a1 = s.query(A).all()[0]
+ if event_name == "refresh":
+ s.refresh(a1)
+ s.close()
+
@_combinations
def test_flag_resolves(self, target, event_name, fn):
A = self.classes.A