From bee38551f35607d630701e2a317ef3d32c3a7f37 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 17 Oct 2020 16:33:23 +0200 Subject: [PATCH] outposts: fix tokens without identifier not loading in the UI --- .../0009_fix_missing_token_identifier.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 passbook/outposts/migrations/0009_fix_missing_token_identifier.py diff --git a/passbook/outposts/migrations/0009_fix_missing_token_identifier.py b/passbook/outposts/migrations/0009_fix_missing_token_identifier.py new file mode 100644 index 000000000..91025d556 --- /dev/null +++ b/passbook/outposts/migrations/0009_fix_missing_token_identifier.py @@ -0,0 +1,25 @@ +# Generated by Django 3.1.2 on 2020-10-17 14:26 + +from django.apps.registry import Apps +from django.db import migrations +from django.db.backends.base.schema import BaseDatabaseSchemaEditor + + +def fix_missing_token_identifier(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): + Outpost = apps.get_model("passbook_outposts", "Outpost") + for outpost in Outpost.objects.using(schema_editor.connection.alias).all(): + token = outpost.token + if token.identifier != outpost.token_identifier: + token.identifier = outpost.token_identifier + token.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ("passbook_outposts", "0008_auto_20201014_1547"), + ] + + operations = [ + migrations.RunPython(fix_missing_token_identifier), + ]