diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-06-14 15:41:31 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-06-14 16:16:06 -0400 |
commit | 042bccd2e4d6fbfcdf70ede760b29f78771f4b22 (patch) | |
tree | 9662d95a33d7c24759208e3831f15b7b406cf953 /lib/sqlalchemy/ext/mutable.py | |
parent | bcd03652c45e1638aaadc398d990696a49f56dbb (diff) | |
download | sqlalchemy-042bccd2e4d6fbfcdf70ede760b29f78771f4b22.tar.gz |
pickle mutable parents according to key
Fixed bug in :class:`.Mutable` where pickling and unpickling of an ORM
mapped instance would not correctly restore state for mappings that
contained multiple :class:`.Mutable`-enabled attributes.
Fixes: #8133
Change-Id: I508763e0df0d7a624e1169f9a46d7f25404add1e
Diffstat (limited to 'lib/sqlalchemy/ext/mutable.py')
-rw-r--r-- | lib/sqlalchemy/ext/mutable.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/sqlalchemy/ext/mutable.py b/lib/sqlalchemy/ext/mutable.py index ba7f9b0a4..1ae5aee8b 100644 --- a/lib/sqlalchemy/ext/mutable.py +++ b/lib/sqlalchemy/ext/mutable.py @@ -355,6 +355,7 @@ pickling process of the parent's object-relational state so that the :meth:`MutableBase._parents` collection is restored to all ``Point`` objects. """ +from collections import defaultdict import weakref from .. import event @@ -496,12 +497,12 @@ class MutableBase: val = state.dict.get(key, None) if val is not None: if "ext.mutable.values" not in state_dict: - state_dict["ext.mutable.values"] = [] - state_dict["ext.mutable.values"].append(val) + state_dict["ext.mutable.values"] = defaultdict(list) + state_dict["ext.mutable.values"][key].append(val) def unpickle(state, state_dict): if "ext.mutable.values" in state_dict: - for val in state_dict["ext.mutable.values"]: + for val in state_dict["ext.mutable.values"][key]: val._parents[state] = key event.listen(parent_cls, "load", load, raw=True, propagate=True) |