diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-10-14 18:06:13 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-10-14 18:06:13 +0000 |
| commit | b56ed8ccb84fb4e173930696ed052acdff5cc3ad (patch) | |
| tree | 2fa476aca78bf83355d3b3bbd50ff7179d87330e /lib | |
| parent | dda6a5f5a88a04d34b973cfb7c0f6d89d4b0e44f (diff) | |
| download | sqlalchemy-b56ed8ccb84fb4e173930696ed052acdff5cc3ad.tar.gz | |
- backref remove object operation doesn't fail if the other-side
collection doesn't contain the item, supports noload collections
[ticket:813]
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sqlalchemy/orm/attributes.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index 714b00376..4b64d52e3 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -520,7 +520,13 @@ class GenericBackrefExtension(interfaces.AttributeExtension): if oldchild is child: return if oldchild is not None: - getattr(oldchild.__class__, self.key).impl.remove(oldchild._state, obj, initiator) + # With lazy=None, there's no guarantee that the full collection is + # present when updating via a backref. + impl = getattr(oldchild.__class__, self.key).impl + try: + impl.remove(oldchild._state, obj, initiator) + except (ValueError, KeyError, IndexError): + pass if child is not None: getattr(child.__class__, self.key).impl.append(child._state, obj, initiator) |
