diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-08-02 23:20:06 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-08-04 12:40:11 -0400 |
| commit | e22d2b089fad1f79d53bc6238626f32f0e796ad0 (patch) | |
| tree | 46997483eceb659d61b4bc00033624a7aef4b999 /lib/sqlalchemy/util/langhelpers.py | |
| parent | a4e0995dc817acda7d669b8925c9bc3defdb660b (diff) | |
| download | sqlalchemy-e22d2b089fad1f79d53bc6238626f32f0e796ad0.tar.gz | |
Strong reference listen function wrapped by "once"
Fixed issue in event system where using the ``once=True`` flag with
dynamically generated listener functions would cause event registration of
future events to fail if those listener functions were garbage collected
after they were used, due to an assumption that a listened function is
strongly referenced. The "once" wrapped is now modified to strongly
reference the inner function persistently, and documentation is updated
that using "once" does not imply automatic de-registration of listener
functions.
Fixes: #4794
Change-Id: I06388083d1633dcc89e8919eb1e51270f966df38
Diffstat (limited to 'lib/sqlalchemy/util/langhelpers.py')
| -rw-r--r-- | lib/sqlalchemy/util/langhelpers.py | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py index d923a6aa1..0e0e3f4df 100644 --- a/lib/sqlalchemy/util/langhelpers.py +++ b/lib/sqlalchemy/util/langhelpers.py @@ -1459,6 +1459,9 @@ def only_once(fn): once = [fn] def go(*arg, **kw): + # strong reference fn so that it isn't garbage collected, + # which interferes with the event system's expectations + strong_fn = fn # noqa if once: once_fn = once.pop() return once_fn(*arg, **kw) |
