From 517b8f62b881081d62466cb25c731f852d859223 Mon Sep 17 00:00:00 2001 From: Ivan Klass Date: Tue, 3 Sep 2024 15:10:25 +0200 Subject: [PATCH] More safe suppress of pickle-to-json data migration --- constance/migrations/0003_drop_pickle.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/constance/migrations/0003_drop_pickle.py b/constance/migrations/0003_drop_pickle.py index 91e584c1..5e37a229 100644 --- a/constance/migrations/0003_drop_pickle.py +++ b/constance/migrations/0003_drop_pickle.py @@ -42,8 +42,12 @@ def migrate_pickled_data(apps, schema_editor) -> None: # pragma: no cover if value is not None: try: redis_migrated_data[prefixed_key] = dumps(pickle.loads(value)) # noqa: S301 - except pickle.UnpicklingError: - continue + except pickle.UnpicklingError as e: + if value.startswith(b'{"__'): + # Seems like we're facing already migrated data + # Might be related to defaults and when config was accessed while django inits for migration + continue + raise e for prefixed_key, value in redis_migrated_data.items(): _rd.set(prefixed_key, value)