-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[back] fix: settings migration not properly applied
- Loading branch information
1 parent
fa3fb06
commit d7c3962
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
backend/core/migrations/0017_reset_setting_exclude_compared.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
), | ||
] |