Skip to content

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

Clear stale assigned delivery on checkout instance in payload (#19849)

Lukasz Ostrowskiaa2bccc9504d
diff --git a/saleor/webhook/payloads.py b/saleor/webhook/payloads.py
index b4fe973349..8ef4b2f051 100644
--- a/saleor/webhook/payloads.py
+++ b/saleor/webhook/payloads.py
@@ -538,8 +538,8 @@ def generate_checkout_payload(
assigned_delivery = checkout.assigned_delivery
except CheckoutDelivery.DoesNotExist:
# Deleted by a concurrent request after the checkout was fetched; the DB
- # has already nulled the FK (SET_NULL), so treat it as no delivery.
- assigned_delivery = None
+ # has already nulled the FK (SET_NULL), so drop the stale reference.
+ checkout.assigned_delivery = assigned_delivery = None
shipping_method = None
if assigned_delivery and not assigned_delivery.is_external:
diff --git a/saleor/webhook/tests/test_webhook_payloads.py b/saleor/webhook/tests/test_webhook_payloads.py
index a3191a28e1..d147c6caec 100644
--- a/saleor/webhook/tests/test_webhook_payloads.py
+++ b/saleor/webhook/tests/test_webhook_payloads.py
@@ -1548,6 +1548,7 @@ def test_generate_checkout_payload_assigned_delivery_deleted_concurrently(
# then
assert payload["shipping_method"] is None
assert payload["token"] == graphene.Node.to_global_id("Checkout", stale_checkout.pk)
+ assert stale_checkout.assigned_delivery is None
def test_generate_requestor_returns_dict_with_user_id_and_user_type(staff_user, rf):