diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2018-06-01 14:50:25 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2018-10-01 16:54:29 -0400 |
| commit | 11947c3f1fce71a8b383eb1fc9af28a0ee0fdb80 (patch) | |
| tree | c6cc2119ac5ee9771c1bb1699d47eaf5d7e19c59 /lib/sqlalchemy/ext | |
| parent | 29d54ab69b689c2bc4b9be8273f4c0a96e37153f (diff) | |
| download | sqlalchemy-11947c3f1fce71a8b383eb1fc9af28a0ee0fdb80.tar.gz | |
Strong reference parent object in association proxy
Considering the reversal of #597 as well as
84420a1d0fe09d7a45e878e853aa9f5258561f8b as I am unable to reproduce
the original issues from that release.
The long-standing behavior of the association proxy collection maintaining
only a weak reference to the parent object is reverted; the proxy will now
maintain a strong reference to the parent for as long as the proxy
collection itself is also in memory, eliminating the "stale association
proxy" error. This change is being made on an experimental basis to see if
any use cases arise where it causes side effects.
Change-Id: I051334be90a343dd0e8a1f35e072075eb14b14a7
Fixes: #4268
Diffstat (limited to 'lib/sqlalchemy/ext')
| -rw-r--r-- | lib/sqlalchemy/ext/associationproxy.py | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/lib/sqlalchemy/ext/associationproxy.py b/lib/sqlalchemy/ext/associationproxy.py index acf13df46..1c28b10a1 100644 --- a/lib/sqlalchemy/ext/associationproxy.py +++ b/lib/sqlalchemy/ext/associationproxy.py @@ -14,7 +14,6 @@ See the example ``examples/association/proxied_association.py``. """ import operator -import weakref from .. import exc, orm, util from ..orm import collections, interfaces from ..sql import or_ @@ -637,22 +636,17 @@ class AssociationProxyInstance(object): class _lazy_collection(object): def __init__(self, obj, target): - self.ref = weakref.ref(obj) + self.parent = obj self.target = target def __call__(self): - obj = self.ref() - if obj is None: - raise exc.InvalidRequestError( - "stale association proxy, parent object has gone out of " - "scope") - return getattr(obj, self.target) + return getattr(self.parent, self.target) def __getstate__(self): - return {'obj': self.ref(), 'target': self.target} + return {'obj': self.parent, 'target': self.target} def __setstate__(self, state): - self.ref = weakref.ref(state['obj']) + self.parent = state['obj'] self.target = state['target'] |
