Skip to content

Commit

Permalink
[back] fix: settings migration not properly applied
Browse files Browse the repository at this point in the history
  • Loading branch information
GresilleSiffle committed Dec 19, 2024
1 parent fa3fb06 commit d7c3962
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions backend/core/migrations/0017_reset_setting_exclude_compared.py
Original file line number Diff line number Diff line change
@@ -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
),
]

0 comments on commit d7c3962

Please sign in to comment.