]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Expect collected weak reference in ORM listener
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 22 Sep 2020 13:00:44 +0000 (09:00 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 22 Sep 2020 13:00:44 +0000 (09:00 -0400)
CI is showing that this listener may be triggered
when the target, a mapped class, has been garbage collected.

I'm not able to reproduce this locally.

Change-Id: Iad96c088a9a3dc28c4bcd716e293c03d3b312efd

lib/sqlalchemy/orm/events.py

index ec907c63e7d69169d00c8f6c99bfdc14f102fda7..0349c445cea0c0360aa14ad8b45d06cdfe43fa1d 100644 (file)
@@ -67,6 +67,9 @@ class InstrumentationEvents(event.Events):
 
         def listen(target_cls, *arg):
             listen_cls = target()
+            if listen_cls is None:
+                return None
+
             if propagate and issubclass(target_cls, listen_cls):
                 return fn(target_cls, *arg)
             elif not propagate and target_cls is listen_cls: