Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
FIX for migration from 3.17 version (#14786)
Michał Macioszczyke2031f0dc458
diff --git a/saleor/discount/migrations/0055_vouchercode.py b/saleor/discount/migrations/0055_vouchercode.pyindex 4db3021fe6..d44ceccd46 100644--- a/saleor/discount/migrations/0055_vouchercode.py+++ b/saleor/discount/migrations/0055_vouchercode.py@@ -48,4 +48,12 @@ class Migration(migrations.Migration):""",reverse_sql=migrations.RunSQL.noop,),+ migrations.RunSQL(+ sql="""+ ALTER TABLE discount_vouchercode+ ALTER COLUMN created_at+ SET DEFAULT CURRENT_TIMESTAMP;+ """,+ reverse_sql=migrations.RunSQL.noop,+ ),]diff --git a/saleor/discount/migrations/0065_vouchercode_created_at_check.py b/saleor/discount/migrations/0065_vouchercode_created_at_check.pynew file mode 100644index 0000000000..03f9b982c1--- /dev/null+++ b/saleor/discount/migrations/0065_vouchercode_created_at_check.py@@ -0,0 +1,21 @@+# Generated by Django 3.2.23 on 2023-11-17 08:08++from django.db import migrations+++class Migration(migrations.Migration):+ dependencies = [+ ("discount", "0064_alter_promotionrule_catalogue_predicate"),+ ]++ operations = [+ migrations.RunSQL(+ sql=(+ """+ ALTER TABLE discount_vouchercode+ ADD COLUMN IF NOT EXISTS created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;+ """+ ),+ reverse_sql=migrations.RunSQL.noop,+ ),+ ]diff --git a/saleor/discount/migrations/0069_merge_20231117_0959.py b/saleor/discount/migrations/0069_merge_20231117_0959.pynew file mode 100644index 0000000000..c7ee4b7aa7--- /dev/null+++ b/saleor/discount/migrations/0069_merge_20231117_0959.py@@ -0,0 +1,12 @@+# Generated by Django 3.2.23 on 2023-11-17 09:59++from django.db import migrations+++class Migration(migrations.Migration):+ dependencies = [+ ("discount", "0065_vouchercode_created_at_check"),+ ("discount", "0068_merge_20231106_1013"),+ ]++ operations = []diff --git a/saleor/graphql/discount/dataloaders.py b/saleor/graphql/discount/dataloaders.pyindex b56bd1a10f..a0b1a7da6c 100644--- a/saleor/graphql/discount/dataloaders.py+++ b/saleor/graphql/discount/dataloaders.py@@ -2,6 +2,7 @@ from collections import defaultdictfrom typing import Optionalfrom django.db.models import Exists, F, OuterRef, Sum+from django.db.models.functions import Coalescefrom promise import Promisefrom ...channel.models import Channel@@ -73,7 +74,7 @@ class UsedByVoucherIDLoader(DataLoader):vouchers = (Voucher.objects.using(self.database_connection_name).filter(id__in=keys)- .annotate(max_used=Sum("codes__used"))+ .annotate(max_used=Coalesce(Sum("codes__used"), 0)))vouchers_map = {}for voucher in vouchers: