From: Mike Bayer Date: Tue, 22 Sep 2020 13:00:44 +0000 (-0400) Subject: Expect collected weak reference in ORM listener X-Git-Tag: rel_1_4_0b1~83 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=468766d6bac1e54a59c5f7d7167467dbc7d29a82;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Expect collected weak reference in ORM listener 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 --- diff --git a/lib/sqlalchemy/orm/events.py b/lib/sqlalchemy/orm/events.py index ec907c63e7..0349c445ce 100644 --- a/lib/sqlalchemy/orm/events.py +++ b/lib/sqlalchemy/orm/events.py @@ -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: