Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add order_by pk to InvoicesByOrderIdLoader. (#12950)

Piotr Zabieglik01c554189e1f
diff --git a/saleor/graphql/invoice/dataloaders.py b/saleor/graphql/invoice/dataloaders.py
index 712206e9b6..a0c957b5f6 100644
--- a/saleor/graphql/invoice/dataloaders.py
+++ b/saleor/graphql/invoice/dataloaders.py
@@ -8,8 +8,10 @@ class InvoicesByOrderIdLoader(DataLoader):
context_key = "invoices_by_order_id"
def batch_load(self, keys):
- invoices = Invoice.objects.using(self.database_connection_name).filter(
- order_id__in=keys
+ invoices = (
+ Invoice.objects.using(self.database_connection_name)
+ .filter(order_id__in=keys)
+ .order_by("pk")
)
invoices_by_order_map = defaultdict(list)
for invoice in invoices:
diff --git a/saleor/invoice/migrations/0009_alter_invoice_options.py b/saleor/invoice/migrations/0009_alter_invoice_options.py
new file mode 100644
index 0000000000..7191d1d2af
--- /dev/null
+++ b/saleor/invoice/migrations/0009_alter_invoice_options.py
@@ -0,0 +1,16 @@
+# Generated by Django 3.2.18 on 2023-05-29 08:22
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("invoice", "0008_rewrite_invoice_order_relations"),
+ ]
+
+ operations = [
+ migrations.AlterModelOptions(
+ name="invoice",
+ options={"ordering": ("pk",)},
+ ),
+ ]
diff --git a/saleor/invoice/models.py b/saleor/invoice/models.py
index fde26775d9..0e67d1f6b7 100644
--- a/saleor/invoice/models.py
+++ b/saleor/invoice/models.py
@@ -50,6 +50,9 @@ class Invoice(ModelWithMetadata, Job):
if url is not None:
self.external_url = url
+ class Meta(ModelWithMetadata.Meta):
+ ordering = ("pk",)
+
class InvoiceEvent(models.Model):
"""Model used to store events that happened during the invoice lifecycle."""