]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
add fallback for old mutable format
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 24 Jun 2022 14:31:46 +0000 (10:31 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 24 Jun 2022 14:32:29 +0000 (10:32 -0400)
Fixed regression caused by :ticket:`8133` where the pickle format for
mutable attributes was changed, without a fallback to recognize the old
format, causing in-place upgrades of SQLAlchemy to no longer be able to
read pickled data from previous versions. A check plus a fallback for the
old format is now in place.

Fixes: #8133
Change-Id: I9029729b4bc56c8b3145797869229eeff48a3b3b
(cherry picked from commit 271c38fd15b94d8acd0e6f054c8001b22535844e)

doc/build/changelog/unreleased_14/mutable_fix.rst [new file with mode: 0644]
lib/sqlalchemy/ext/mutable.py

diff --git a/doc/build/changelog/unreleased_14/mutable_fix.rst b/doc/build/changelog/unreleased_14/mutable_fix.rst
new file mode 100644 (file)
index 0000000..2c96878
--- /dev/null
@@ -0,0 +1,9 @@
+.. change::
+    :tags: bug, orm, regression
+    :tickets: 8133
+
+    Fixed regression caused by :ticket:`8133` where the pickle format for
+    mutable attributes was changed, without a fallback to recognize the old
+    format, causing in-place upgrades of SQLAlchemy to no longer be able to
+    read pickled data from previous versions. A check plus a fallback for the
+    old format is now in place.
index 934ac37a0560a82bc31c8e677cab5b53478641ee..cbec06a31fec353cf9d8386903c3dce2a9d00e40 100644 (file)
@@ -502,8 +502,14 @@ class MutableBase(object):
 
         def unpickle(state, state_dict):
             if "ext.mutable.values" in state_dict:
-                for val in state_dict["ext.mutable.values"][key]:
-                    val._parents[state] = key
+                collection = state_dict["ext.mutable.values"]
+                if isinstance(collection, list):
+                    # legacy format
+                    for val in collection:
+                        val._parents[state] = key
+                else:
+                    for val in state_dict["ext.mutable.values"][key]:
+                        val._parents[state] = key
 
         event.listen(parent_cls, "load", load, raw=True, propagate=True)
         event.listen(