From d7c3962ae1dae70f8787e8580bd2798584425844 Mon Sep 17 00:00:00 2001 From: Gresille&Siffle <39056254+GresilleSiffle@users.noreply.github.com> Date: Thu, 19 Dec 2024 17:17:44 +0100 Subject: [PATCH] [back] fix: settings migration not properly applied --- .../0017_reset_setting_exclude_compared.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 backend/core/migrations/0017_reset_setting_exclude_compared.py diff --git a/backend/core/migrations/0017_reset_setting_exclude_compared.py b/backend/core/migrations/0017_reset_setting_exclude_compared.py new file mode 100644 index 0000000000..9b30733247 --- /dev/null +++ b/backend/core/migrations/0017_reset_setting_exclude_compared.py @@ -0,0 +1,40 @@ +# Generated by Django 4.2.17 on 2024-12-19 16:06 + +from django.db import migrations + + +def copy_setting(user, from_key, to_key): + try: + value = user.settings["videos"][from_key] + except KeyError: + return False + + user.settings["videos"][to_key] = value + return True + + +def migrate_reset_exclude_compared(apps, schema_editor): + """ + This migration fixes the previous 0016. + """ + User = apps.get_model("core", "User") + for user in User.objects.iterator(): + if "videos" not in user.settings: + continue + + copy_setting(user, "recommendations__default_unsafe", "feed_foryou__unsafe") + user.settings["videos"].pop("feed_foryou__exclude_compared_entities", None) + user.save(update_fields=["settings"]) + + +class Migration(migrations.Migration): + + dependencies = [ + ("core", "0016_migrate_reco_settings"), + ] + + operations = [ + migrations.RunPython( + code=migrate_reset_exclude_compared, reverse_code=migrations.RunPython.noop + ), + ]