diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2018-10-01 21:34:05 -0400 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@ci.zzzcomputing.com> | 2018-10-01 21:34:05 -0400 |
| commit | d9c6bbbd9499dcf4022cf9fe37877f49bf45b768 (patch) | |
| tree | a17fe1c6c12bde2ac10ba53ee5bca1a255e65b88 /lib | |
| parent | 313879d6adedd4fd2a07a4ec30530766f3016885 (diff) | |
| parent | 11947c3f1fce71a8b383eb1fc9af28a0ee0fdb80 (diff) | |
| download | sqlalchemy-d9c6bbbd9499dcf4022cf9fe37877f49bf45b768.tar.gz | |
Merge "Strong reference parent object in association proxy"
Diffstat (limited to 'lib')
| -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'] |
