summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/ext/mutable.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-06-14 15:41:31 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2022-06-14 16:16:43 -0400
commitf4188f571df11905bb4aab107b45298c7130a0ec (patch)
tree4c82e421ac4338c8e8d92175a10fb6384b22db29 /lib/sqlalchemy/ext/mutable.py
parentbef0cb2537a58eaefd6c9e4eb721588f97da1343 (diff)
downloadsqlalchemy-f4188f571df11905bb4aab107b45298c7130a0ec.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 (cherry picked from commit 69020e416d9836fcc0bc99fcf008563263fb86f3)
Diffstat (limited to 'lib/sqlalchemy/ext/mutable.py')
-rw-r--r--lib/sqlalchemy/ext/mutable.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/sqlalchemy/ext/mutable.py b/lib/sqlalchemy/ext/mutable.py
index b5217a426..934ac37a0 100644
--- a/lib/sqlalchemy/ext/mutable.py
+++ b/lib/sqlalchemy/ext/mutable.py
@@ -354,6 +354,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(object):
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)