Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
fix/migrations: Respect POPULATE_DEFAULTS in account migration 0103 (#19845)
Mikolaj Stempniewiczcf43e116e2a1
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e968989e73..1d2ac41653 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -75,6 +75,7 @@ All notable, unreleased changes to this project will be documented in this file.### Fixes+- Fixed migration `account.0103_create_default_customer_type` to respect `POPULATE_DEFAULTS`; the default customer type is no longer created when defaults are disabled, and the post-migration assignment task skips when none exists.- Fixed `appCreate` and `appUpdate` failing with an unhandled error when `permissions` was `null` or omitted. `appCreate` now creates an app with no permissions, and `appUpdate` leaves the app's existing permissions untouched. Passing an empty list to `appUpdate` still clears them.- Fixed the `set_user_search_document_values` data migration task failing with a statement timeout on large user tables.diff --git a/saleor/account/migrations/0103_create_default_customer_type.py b/saleor/account/migrations/0103_create_default_customer_type.pyindex 9c4419e031..215daf3564 100644--- a/saleor/account/migrations/0103_create_default_customer_type.py+++ b/saleor/account/migrations/0103_create_default_customer_type.py@@ -1,7 +1,10 @@+from django.conf import settingsfrom django.db import migrationsdef create_default_customer_type(apps, _schema_editor):+ if not settings.POPULATE_DEFAULTS:+ returnCustomerType = apps.get_model("account", "CustomerType")CustomerType.objects.get_or_create(is_default=True,diff --git a/saleor/account/migrations/tasks/saleor3_23.py b/saleor/account/migrations/tasks/saleor3_23.pyindex 1a8bbcc910..f59a1a9f67 100644--- a/saleor/account/migrations/tasks/saleor3_23.py+++ b/saleor/account/migrations/tasks/saleor3_23.py@@ -4,6 +4,7 @@ from django.db import transactionfrom ....celeryconf import appfrom ....core.db.connection import allow_writer+from ...exceptions import NoDefaultCustomerTypefrom ...lock_objects import user_qs_select_for_updatefrom ...models import CustomerEvent, Userfrom ...utils import get_default_customer_type@@ -70,7 +71,11 @@ ASSIGN_DEFAULT_CUSTOMER_TYPE_BATCH_SIZE = 100def assign_default_customer_type_to_users_task():"""Assign the default customer type to users that don't have any type yet."""- default_customer_type = get_default_customer_type()+ try:+ default_customer_type = get_default_customer_type()+ except NoDefaultCustomerType:+ task_logger.info("No default customer type, skipping assignment")+ returnwith transaction.atomic():batch_pks = list(diff --git a/saleor/account/tests/test_customer_type.py b/saleor/account/tests/test_customer_type.pyindex d0988f862e..525489da98 100644--- a/saleor/account/tests/test_customer_type.py+++ b/saleor/account/tests/test_customer_type.py@@ -133,10 +133,16 @@ def test_assign_default_customer_type_task_processes_all_batches(@pytest.mark.django_db-def test_assign_default_customer_type_task_raises_when_default_is_missing():- # given+def test_assign_default_customer_type_task_skips_when_default_is_missing(+ customer_user,+):+ # given a user without a type and no customer types at all+ User.objects.filter(pk=customer_user.pk).update(customer_type=None)CustomerType.objects.all().delete()- # when / then- with pytest.raises(NoDefaultCustomerType):- assign_default_customer_type_to_users_task()+ # when+ assign_default_customer_type_to_users_task()++ # then+ customer_user.refresh_from_db()+ assert customer_user.customer_type is None