Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix account migration (#17882)
Iga Karbowiak68008240bbea
diff --git a/saleor/account/migrations/0091_populate_user_number_of_orders.py b/saleor/account/migrations/0091_populate_user_number_of_orders.pyindex 1faa07c5db..2c98e1dfbc 100644--- a/saleor/account/migrations/0091_populate_user_number_of_orders.py+++ b/saleor/account/migrations/0091_populate_user_number_of_orders.py@@ -8,5 +8,5 @@ class Migration(migrations.Migration):("account", "0090_user_number_of_orders"),]- # empty migration for consistency, the populating task called in 0094+ # empty migration for consistency, the populating task called in 0095operations = []diff --git a/saleor/account/migrations/0094_repopulate_user_number_of_orders.py b/saleor/account/migrations/0094_repopulate_user_number_of_orders.pyindex 3bcbdc166d..6d38032961 100644--- a/saleor/account/migrations/0094_repopulate_user_number_of_orders.py+++ b/saleor/account/migrations/0094_repopulate_user_number_of_orders.py@@ -1,18 +1,6 @@# Generated by Django 5.2.1 on 2025-06-27 07:09-from django.apps import apps as registryfrom django.db import migrations-from django.db.models.signals import post_migrate--from .tasks.saleor3_22 import populate_user_number_of_orders_task---def populate_user_number_of_orders(apps, _schema_editor):- def on_migrations_complete(sender=None, **kwargs):- populate_user_number_of_orders_task.delay()-- sender = registry.get_app_config("order")- post_migrate.connect(on_migrations_complete, weak=False, sender=sender)class Migration(migrations.Migration):@@ -20,9 +8,5 @@ class Migration(migrations.Migration):("account", "0093_user_user_number_of_orders_idx"),]- operations = [- migrations.RunPython(- populate_user_number_of_orders,- reverse_code=migrations.RunPython.noop,- )- ]+ # empty migration for consistency, the populating task called in 0095+ operations = []diff --git a/saleor/account/migrations/0095_repopulate_user_number_of_orders.py b/saleor/account/migrations/0095_repopulate_user_number_of_orders.pynew file mode 100644index 0000000000..72e0dd24dc--- /dev/null+++ b/saleor/account/migrations/0095_repopulate_user_number_of_orders.py@@ -0,0 +1,28 @@+# Generated by Django 5.2.1 on 2025-06-27 12:53++from django.apps import apps as registry+from django.db import migrations+from django.db.models.signals import post_migrate++from .tasks.saleor3_22 import populate_user_number_of_orders_task+++def populate_user_number_of_orders(apps, _schema_editor):+ def on_migrations_complete(sender=None, **kwargs):+ populate_user_number_of_orders_task.delay()++ sender = registry.get_app_config("order")+ post_migrate.connect(on_migrations_complete, weak=False, sender=sender)+++class Migration(migrations.Migration):+ dependencies = [+ ("account", "0094_repopulate_user_number_of_orders"),+ ]++ operations = [+ migrations.RunPython(+ populate_user_number_of_orders,+ reverse_code=migrations.RunPython.noop,+ )+ ]diff --git a/saleor/account/migrations/tasks/saleor3_22.py b/saleor/account/migrations/tasks/saleor3_22.pyindex 4d183f30e6..6673b03b3b 100644--- a/saleor/account/migrations/tasks/saleor3_22.py+++ b/saleor/account/migrations/tasks/saleor3_22.py@@ -38,7 +38,7 @@ def populate_user_number_of_orders_task(user_pk=0):)users_to_update = []for user in users:- total_orders = user_total_orders.get(user.id)+ total_orders = user_total_orders.get(user.id, 0)# Skip if the total orders count is the same to avoid unnecessary updatesif total_orders == user.number_of_orders: