Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Skip obsolete payload save and cleanup for successful sync webhooks (#16632)
Cezary Miączc3d94f92dba5
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 00196c9271..3f95a6378b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -30,3 +30,4 @@ All notable, unreleased changes to this project will be documented in this file.- Added validation for tax data received from tax app - #16720 by @zedzior- Fixed order-level discounts handling when using tax app for tax calculation - #16696 by @zedzior- Fixed bug when manual line discount doesn't override line-level vouchers - #16738 by @zedzior+- Skipped obsolete payload save and cleanup for successful sync webhooks - #16632 by @cmiaczdiff --git a/saleor/checkout/tests/test_actions.py b/saleor/checkout/tests/test_actions.pyindex 26fae7938a..781bc58a34 100644--- a/saleor/checkout/tests/test_actions.py+++ b/saleor/checkout/tests/test_actions.py@@ -665,7 +665,9 @@ def test_call_checkout_event_triggers_sync_webhook_when_needed(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_created_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call, tax_delivery_call = (mocked_send_webhook_request_sync.mock_calls@@ -749,7 +751,9 @@ def test_call_checkout_event_skips_tax_webhook_when_not_expired(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_created_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_calls@@ -984,7 +988,9 @@ def test_call_checkout_info_event_triggers_sync_webhook_when_needed(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_created_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call, tax_delivery_call = (mocked_send_webhook_request_sync.mock_calls@@ -1079,7 +1085,9 @@ def test_call_checkout_info_event_skips_tax_webhook_when_not_expired(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_created_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_calls@@ -1285,7 +1293,9 @@ def test_transaction_amounts_for_checkout_fully_paid_triggers_sync_webhook(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_fully_paid_webhook.id+ ).exists()tax_delivery_call, shipping_methods_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_calls@@ -1414,7 +1424,9 @@ def test_call_checkout_events_triggers_sync_webhook_when_needed(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_created_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call, tax_delivery_call = (mocked_send_webhook_request_sync.mock_calls@@ -1506,7 +1518,9 @@ def test_call_checkout_events_skips_tax_webhook_when_not_expired(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_created_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/core/models.py b/saleor/core/models.pyindex 26dce96294..83717af1b9 100644--- a/saleor/core/models.py+++ b/saleor/core/models.py@@ -189,6 +189,12 @@ class EventPayload(models.Model):file_path = safe_join(prefix, file_name)self.payload_file.save(file_path, ContentFile(payload_bytes))+ def save_as_file(self):+ payload_data = self.payload+ self.payload = ""+ self.save()+ self.save_payload_file(payload_data)+class EventDelivery(models.Model):created_at = models.DateTimeField(auto_now_add=True)diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_add_promo_code.py b/saleor/graphql/checkout/tests/mutations/test_checkout_add_promo_code.pyindex 6432249914..5de2f5c5e1 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_add_promo_code.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_add_promo_code.py@@ -1598,7 +1598,9 @@ def test_checkout_add_voucher_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_updated_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call, tax_delivery_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_billing_address_update.py b/saleor/graphql/checkout/tests/mutations/test_checkout_billing_address_update.pyindex 2b62de82e1..578094c895 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_billing_address_update.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_billing_address_update.py@@ -706,7 +706,9 @@ def test_checkout_billing_address_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_updated_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call, tax_delivery_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_create.py b/saleor/graphql/checkout/tests/mutations/test_checkout_create.pyindex 8a06bea5c4..e2075c217b 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_create.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_create.py@@ -2720,7 +2720,9 @@ def test_checkout_create_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_created_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call, tax_delivery_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_customer_attach.py b/saleor/graphql/checkout/tests/mutations/test_checkout_customer_attach.pyindex 7ce8075ca6..fc6b928f7d 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_customer_attach.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_customer_attach.py@@ -297,7 +297,9 @@ def test_checkout_customer_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_updated_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call, tax_delivery_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_customer_detach.py b/saleor/graphql/checkout/tests/mutations/test_checkout_customer_detach.pyindex ddb1705684..903bcef6d2 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_customer_detach.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_customer_detach.py@@ -173,7 +173,9 @@ def test_checkout_customer_detach_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_updated_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call, tax_delivery_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_customer_note_update.py b/saleor/graphql/checkout/tests/mutations/test_checkout_customer_note_update.pyindex f281879696..151b1e52ea 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_customer_note_update.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_customer_note_update.py@@ -137,7 +137,9 @@ def test_checkout_customer_note_update_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_updated_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call, tax_delivery_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_delivery_method_update.py b/saleor/graphql/checkout/tests/mutations/test_checkout_delivery_method_update.pyindex 39653969c7..98100a915c 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_delivery_method_update.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_delivery_method_update.py@@ -1069,7 +1069,9 @@ def test_checkout_delivery_method_update_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_updated_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call, tax_delivery_call = (mocked_send_webhook_request_sync.mock_calls@@ -1162,7 +1164,9 @@ def test_checkout_delivery_method_update_cc_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_updated_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call, tax_delivery_call = (mocked_send_webhook_request_sync.mock_calls@@ -1267,7 +1271,9 @@ def test_checkout_delivery_method_update_external_shipping_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_updated_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call, tax_delivery_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_email_update.py b/saleor/graphql/checkout/tests/mutations/test_checkout_email_update.pyindex 2f5d7075b5..de5c64a716 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_email_update.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_email_update.py@@ -144,7 +144,9 @@ def test_checkout_email_update_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_updated_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call, tax_delivery_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_language_code_update.py b/saleor/graphql/checkout/tests/mutations/test_checkout_language_code_update.pyindex 4a0fcec495..49e20a51d2 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_language_code_update.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_language_code_update.py@@ -126,7 +126,9 @@ def test_checkout_update_language_code_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_updated_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call, tax_delivery_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_line_delete.py b/saleor/graphql/checkout/tests/mutations/test_checkout_line_delete.pyindex 872f79c57f..23e87fb974 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_line_delete.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_line_delete.py@@ -273,7 +273,9 @@ def test_checkout_line_delete_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_updated_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call, tax_delivery_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_lines_add.py b/saleor/graphql/checkout/tests/mutations/test_checkout_lines_add.pyindex 7ba565fb58..dd8f70ca4f 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_lines_add.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_lines_add.py@@ -1824,7 +1824,9 @@ def test_checkout_lines_add_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_updated_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call, tax_delivery_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_lines_delete.py b/saleor/graphql/checkout/tests/mutations/test_checkout_lines_delete.pyindex b2ad769225..461c2eef90 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_lines_delete.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_lines_delete.py@@ -263,7 +263,9 @@ def test_checkout_lines_delete_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_updated_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call, tax_delivery_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_lines_update.py b/saleor/graphql/checkout/tests/mutations/test_checkout_lines_update.pyindex 74a54a6eba..c672a99e7b 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_lines_update.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_lines_update.py@@ -1428,7 +1428,9 @@ def test_checkout_lines_update_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_updated_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call, tax_delivery_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_remove_promo_code.py b/saleor/graphql/checkout/tests/mutations/test_checkout_remove_promo_code.pyindex e6ad50511e..4a4b75fd8c 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_remove_promo_code.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_remove_promo_code.py@@ -783,7 +783,9 @@ def test_checkout_remove_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_updated_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call, tax_delivery_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_address_update.py b/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_address_update.pyindex 643d9cb5a4..d732d78883 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_address_update.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_address_update.py@@ -1138,7 +1138,9 @@ def test_checkout_shipping_address_update_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_updated_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call, tax_delivery_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_method_update.py b/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_method_update.pyindex 110c7b80ef..039049ac96 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_method_update.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_method_update.py@@ -540,7 +540,9 @@ def test_checkout_shipping_method_update_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_updated_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call, tax_delivery_call = (mocked_send_webhook_request_sync.mock_calls@@ -641,7 +643,9 @@ def test_checkout_shipping_method_update_external_shipping_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_updated_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call, tax_delivery_call = (mocked_send_webhook_request_sync.mock_calls@@ -727,7 +731,9 @@ def test_checkout_shipping_method_update_to_none_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_updated_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call, tax_delivery_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/meta/tests/mutations/test_checkout.py b/saleor/graphql/meta/tests/mutations/test_checkout.pyindex fb4e50b621..33313b3262 100644--- a/saleor/graphql/meta/tests/mutations/test_checkout.py+++ b/saleor/graphql/meta/tests/mutations/test_checkout.py@@ -415,7 +415,9 @@ def test_add_metadata_for_checkout_triggers_webhooks_with_checkout_updated(# confirm each sync webhook con was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_updated_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call, tax_delivery_call = (mocked_send_webhook_request_sync.mock_calls@@ -495,7 +497,9 @@ def test_add_metadata_for_checkout_triggers_webhooks_with_updated_metadata(# confirm each sync webhook con was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_metadata_updated_webhook.id+ ).exists()shipping_methods_call, filter_shipping_call, tax_delivery_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/meta/tests/mutations/test_order.py b/saleor/graphql/meta/tests/mutations/test_order.pyindex e82b445ea9..70ee769212 100644--- a/saleor/graphql/meta/tests/mutations/test_order.py+++ b/saleor/graphql/meta/tests/mutations/test_order.py@@ -643,7 +643,9 @@ def test_change_in_public_metadata_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=additional_order_webhook.id+ ).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_calls@@ -718,7 +720,9 @@ def test_change_in_private_metadata_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=additional_order_webhook.id+ ).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/order/tests/mutations/test_draft_order_complete.py b/saleor/graphql/order/tests/mutations/test_draft_order_complete.pyindex 1c4335b446..2198440e94 100644--- a/saleor/graphql/order/tests/mutations/test_draft_order_complete.py+++ b/saleor/graphql/order/tests/mutations/test_draft_order_complete.py@@ -1591,7 +1591,9 @@ def test_draft_order_complete_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=additional_order_webhook.id+ ).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/order/tests/mutations/test_draft_order_create.py b/saleor/graphql/order/tests/mutations/test_draft_order_create.pyindex 745c38b2bb..02671f8da3 100644--- a/saleor/graphql/order/tests/mutations/test_draft_order_create.py+++ b/saleor/graphql/order/tests/mutations/test_draft_order_create.py@@ -3705,7 +3705,9 @@ def test_draft_order_create_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=draft_order_created_webhook.id+ ).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/order/tests/mutations/test_draft_order_update.py b/saleor/graphql/order/tests/mutations/test_draft_order_update.pyindex 45dfa99441..43fa294b98 100644--- a/saleor/graphql/order/tests/mutations/test_draft_order_update.py+++ b/saleor/graphql/order/tests/mutations/test_draft_order_update.py@@ -2330,7 +2330,9 @@ def test_draft_order_update_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=draft_order_updated_webhook.id+ ).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_calls@@ -2417,7 +2419,9 @@ def test_draft_order_update_triggers_webhooks_when_tax_webhook_not_needed(# confirm each sync webhook was called without saving event deliverymocked_send_webhook_request_sync.assert_called_once()- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=draft_order_updated_webhook.id+ ).exists()filter_shipping_call = mocked_send_webhook_request_sync.mock_calls[0]diff --git a/saleor/graphql/order/tests/mutations/test_order_capture.py b/saleor/graphql/order/tests/mutations/test_order_capture.pyindex 34b0516e06..dfe6952384 100644--- a/saleor/graphql/order/tests/mutations/test_order_capture.py+++ b/saleor/graphql/order/tests/mutations/test_order_capture.py@@ -264,7 +264,9 @@ def test_order_capture_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=additional_order_webhook.id+ ).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/order/tests/mutations/test_order_line_delete.py b/saleor/graphql/order/tests/mutations/test_order_line_delete.pyindex 161e38ba5d..e8389e818a 100644--- a/saleor/graphql/order/tests/mutations/test_order_line_delete.py+++ b/saleor/graphql/order/tests/mutations/test_order_line_delete.py@@ -375,7 +375,7 @@ def test_order_line_delete_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(webhook_id=order_webhook.id).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/order/tests/mutations/test_order_line_update.py b/saleor/graphql/order/tests/mutations/test_order_line_update.pyindex d99f66c703..c0c50a3db2 100644--- a/saleor/graphql/order/tests/mutations/test_order_line_update.py+++ b/saleor/graphql/order/tests/mutations/test_order_line_update.py@@ -651,7 +651,7 @@ def test_order_line_update_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(webhook_id=order_webhook.id).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/order/tests/mutations/test_order_lines_create.py b/saleor/graphql/order/tests/mutations/test_order_lines_create.pyindex 87e719df2e..093be12fb4 100644--- a/saleor/graphql/order/tests/mutations/test_order_lines_create.py+++ b/saleor/graphql/order/tests/mutations/test_order_lines_create.py@@ -1314,7 +1314,7 @@ def test_order_lines_create_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(webhook_id=order_webhook.id).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/order/tests/mutations/test_order_note_add.py b/saleor/graphql/order/tests/mutations/test_order_note_add.pyindex e98cae8823..7cee62e96e 100644--- a/saleor/graphql/order/tests/mutations/test_order_note_add.py+++ b/saleor/graphql/order/tests/mutations/test_order_note_add.py@@ -243,7 +243,7 @@ def test_order_note_add_user_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(webhook_id=order_webhook.id).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/order/tests/mutations/test_order_note_update.py b/saleor/graphql/order/tests/mutations/test_order_note_update.pyindex 59fe90b194..7f421a684c 100644--- a/saleor/graphql/order/tests/mutations/test_order_note_update.py+++ b/saleor/graphql/order/tests/mutations/test_order_note_update.py@@ -287,7 +287,7 @@ def test_order_note_update_user_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(webhook_id=order_webhook.id).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/order/tests/mutations/test_order_update.py b/saleor/graphql/order/tests/mutations/test_order_update.pyindex 6660dde794..c5222302d2 100644--- a/saleor/graphql/order/tests/mutations/test_order_update.py+++ b/saleor/graphql/order/tests/mutations/test_order_update.py@@ -576,7 +576,7 @@ def test_order_update_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(webhook_id=order_webhook.id).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/graphql/order/tests/mutations/test_order_update_shipping.py b/saleor/graphql/order/tests/mutations/test_order_update_shipping.pyindex 8f38455a5d..1dabdbaf6e 100644--- a/saleor/graphql/order/tests/mutations/test_order_update_shipping.py+++ b/saleor/graphql/order/tests/mutations/test_order_update_shipping.py@@ -602,7 +602,7 @@ def test_order_update_shipping_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(webhook_id=order_webhook.id).exists()# FIXME: This is the issue with current way of caching filter shipping# webhooks. Mutation calls the webhook to validates the shipping methods.diff --git a/saleor/order/tests/test_order_actions.py b/saleor/order/tests/test_order_actions.pyindex 68bb6f4fce..41d6b4e105 100644--- a/saleor/order/tests/test_order_actions.py+++ b/saleor/order/tests/test_order_actions.py@@ -474,7 +474,9 @@ def test_handle_fully_paid_order_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=additional_order_webhook.id+ ).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_calls@@ -919,7 +921,9 @@ def test_order_refunded_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=additional_order_webhook.id+ ).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_calls@@ -1011,7 +1015,9 @@ def test_order_voided_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=additional_order_webhook.id+ ).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_calls@@ -1203,7 +1209,9 @@ def test_order_awaits_fulfillment_approval_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=additional_order_webhook.id+ ).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_calls@@ -1294,7 +1302,9 @@ def test_order_authorized_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=additional_order_webhook.id+ ).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_calls@@ -1414,7 +1424,9 @@ def test_order_charged_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=additional_order_webhook.id+ ).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_calls@@ -1796,7 +1808,9 @@ def test_order_transaction_updated_for_charged_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=additional_order_webhook.id+ ).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_calls@@ -1905,7 +1919,9 @@ def test_order_transaction_updated_for_authorized_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=additional_order_webhook.id+ ).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_calls@@ -2033,7 +2049,10 @@ def test_order_transaction_updated_for_refunded_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created++ assert not EventDelivery.objects.exclude(+ webhook_id=additional_order_webhook.id+ ).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_calls@@ -2496,7 +2515,7 @@ def test_call_order_event_triggers_sync_webhook(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(webhook_id=order_webhook.id).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_calls@@ -2629,7 +2648,8 @@ def test_call_order_event_missing_filter_shipping_method_webhook()mocked_send_webhook_request_sync.assert_called_once()- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(webhook_id=order_webhook.id).exists()+tax_delivery = mocked_send_webhook_request_sync.mock_calls[0].args[0]assert tax_delivery.webhook_id == tax_webhook.id@@ -2712,7 +2732,7 @@ def test_call_order_event_skips_tax_webhook_when_prices_are_valid(# confirm each sync webhook was called without saving event deliverymocked_send_webhook_request_sync.assert_called_once()- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(webhook_id=order_webhook.id).exists()filter_shipping_call = mocked_send_webhook_request_sync.mock_calls[0]filter_shipping_delivery = filter_shipping_call.args[0]@@ -2800,7 +2820,7 @@ def test_call_order_event_skips_sync_webhooks_when_order_not_editable(retry_kwargs={"max_retries": 5},)assert not mocked_send_webhook_request_sync.called- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(webhook_id=order_webhook.id).exists()mocked_call_event_including_protected_events.assert_called_once_with(ANY, order_with_lines, webhooks={order_webhook})@@ -3037,7 +3057,7 @@ def test_call_order_events_triggers_sync_webhook()# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(webhook_id=order_webhook.id).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_calls@@ -3192,7 +3212,8 @@ def test_call_order_events_missing_filter_shipping_method_webhook(# confirm each sync webhook was called without saving event deliverymocked_send_webhook_request_sync.assert_called_once()- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(webhook_id=order_webhook.id).exists()+tax_delivery = mocked_send_webhook_request_sync.mock_calls[0].args[0]assert tax_delivery.webhook_id == tax_webhook.id@@ -3286,7 +3307,7 @@ def test_call_order_events_skips_tax_webhook_when_prices_are_valid(# confirm each sync webhook was called without saving event deliverymocked_send_webhook_request_sync.assert_called_once()- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(webhook_id=order_webhook.id).exists()filter_shipping_call = mocked_send_webhook_request_sync.mock_calls[0]filter_shipping_delivery = filter_shipping_call.args[0]@@ -3699,7 +3720,9 @@ def test_order_created_triggers_webhooks()# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=additional_order_webhook.id+ ).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_calls@@ -3804,7 +3827,9 @@ def test_order_confirmed_triggers_webhooks(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=additional_order_webhook.id+ ).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/order/tests/test_tasks.py b/saleor/order/tests/test_tasks.pyindex ed9defae45..12aef32cec 100644--- a/saleor/order/tests/test_tasks.py+++ b/saleor/order/tests/test_tasks.py@@ -833,7 +833,9 @@ def test_send_order_updated(# confirm each sync webhook was called without saving event deliveryassert mocked_send_webhook_request_sync.call_count == 2- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exclude(+ webhook_id=additional_order_webhook.id+ ).exists()tax_delivery_call, filter_shipping_call = (mocked_send_webhook_request_sync.mock_callsdiff --git a/saleor/plugins/webhook/tests/test_list_stored_payment_methods_webhook.py b/saleor/plugins/webhook/tests/test_list_stored_payment_methods_webhook.pyindex 5e48eea9e5..38c7039b8a 100644--- a/saleor/plugins/webhook/tests/test_list_stored_payment_methods_webhook.py+++ b/saleor/plugins/webhook/tests/test_list_stored_payment_methods_webhook.py@@ -3,6 +3,7 @@ from unittest import mockimport graphene+from ....core.models import EventDeliveryfrom ....payment.interface import ListStoredPaymentMethodsRequestDatafrom ....settings import WEBHOOK_SYNC_TIMEOUTfrom ....webhook.const import WEBHOOK_CACHE_DEFAULT_TIMEOUT@@ -72,7 +73,7 @@ def test_list_stored_payment_methods_with_static_payload(# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()mocked_cache_get.assert_called_once_with(expected_cache_key)mocked_cache_set.assert_called_once_with(@@ -121,7 +122,7 @@ def test_list_stored_payment_methods_subscription_issuing_principal(# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]delivery_subscription_payload = json.loads(delivery.payload.get_payload())@@ -169,7 +170,7 @@ def test_list_stored_payment_methods_subscription_issuing_principal_as_app(# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]delivery_subscription_payload = json.loads(delivery.payload.get_payload())@@ -231,7 +232,7 @@ def test_list_stored_payment_methods_with_subscription_payload(# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()mocked_cache_get.assert_called_once_with(expected_cache_key)mocked_cache_set.assert_called_once_with(@@ -346,7 +347,7 @@ def test_list_stored_payment_methods_app_returns_incorrect_response(# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()mocked_cache_get.assert_called_once_with(expected_cache_key)assert not mocked_cache_set.calleddiff --git a/saleor/plugins/webhook/tests/test_payment_gateway_initialize_tokenization.py b/saleor/plugins/webhook/tests/test_payment_gateway_initialize_tokenization.pyindex 0e92c7a540..63395a301b 100644--- a/saleor/plugins/webhook/tests/test_payment_gateway_initialize_tokenization.py+++ b/saleor/plugins/webhook/tests/test_payment_gateway_initialize_tokenization.py@@ -4,6 +4,7 @@ from unittest import mockimport grapheneimport pytest+from ....core.models import EventDeliveryfrom ....payment.interface import (PaymentGatewayInitializeTokenizationRequestData,PaymentGatewayInitializeTokenizationResponseData,@@ -74,7 +75,7 @@ def test_payment_gateway_initialize_tokenization_with_static_payload(# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]assert json.loads(delivery.payload.get_payload()) == {@@ -131,7 +132,7 @@ def test_payment_gateway_initialize_tokenization_with_subscription_payload(# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]assert json.loads(delivery.payload.get_payload()) == {@@ -187,7 +188,7 @@ def test_payment_gateway_initialize_tokenization_missing_correct_response_from_w# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()assert response == PaymentGatewayInitializeTokenizationResponseData(result=PaymentGatewayInitializeTokenizationResult.FAILED_TO_DELIVER,@@ -236,7 +237,7 @@ def test_payment_gateway_initialize_tokenization_failure_from_app(# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]assert json.loads(delivery.payload.get_payload()) == {diff --git a/saleor/plugins/webhook/tests/test_payment_method_initialize_tokenization.py b/saleor/plugins/webhook/tests/test_payment_method_initialize_tokenization.pyindex ad39f816c7..b5332ad18a 100644--- a/saleor/plugins/webhook/tests/test_payment_method_initialize_tokenization.py+++ b/saleor/plugins/webhook/tests/test_payment_method_initialize_tokenization.py@@ -4,6 +4,7 @@ from unittest import mockimport grapheneimport pytest+from ....core.models import EventDeliveryfrom ....payment import TokenizedPaymentFlowfrom ....payment.interface import (ListStoredPaymentMethodsRequestData,@@ -84,7 +85,7 @@ def test_payment_method_initialize_tokenization_with_static_payload(# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]assert json.loads(delivery.payload.get_payload()) == {@@ -147,7 +148,7 @@ def test_payment_method_initialize_tokenization_with_subscription_payload(# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]assert json.loads(delivery.payload.get_payload()) == {@@ -209,7 +210,7 @@ def test_payment_method_initialize_tokenization_missing_correct_response_from_we# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()assert response == PaymentMethodTokenizationResponseData(result=PaymentMethodTokenizationResult.FAILED_TO_DELIVER,@@ -260,7 +261,7 @@ def test_payment_method_initialize_tokenization_failure_from_app(# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]assert json.loads(delivery.payload.get_payload()) == {@@ -320,7 +321,7 @@ def test_payment_method_initialize_tokenization_additional_action_required(# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]assert json.loads(delivery.payload.get_payload()) == {@@ -388,7 +389,7 @@ def test_payment_method_initialize_tokenization_missing_required_id(# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]assert json.loads(delivery.payload.get_payload()) == {@@ -505,7 +506,7 @@ def test_expected_result_invalidates_cache_for_app(# thenmocked_request.assert_called()assert mocked_request.mock_calls[-1].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mocked_request.mock_calls[-1].args[0]assert (diff --git a/saleor/plugins/webhook/tests/test_payment_method_process_tokenization.py b/saleor/plugins/webhook/tests/test_payment_method_process_tokenization.pyindex 21d94f0eff..703e19b9d0 100644--- a/saleor/plugins/webhook/tests/test_payment_method_process_tokenization.py+++ b/saleor/plugins/webhook/tests/test_payment_method_process_tokenization.py@@ -4,6 +4,7 @@ from unittest import mockimport grapheneimport pytest+from ....core.models import EventDeliveryfrom ....payment.interface import (ListStoredPaymentMethodsRequestData,PaymentMethodProcessTokenizationRequestData,@@ -86,7 +87,7 @@ def test_payment_method_process_tokenization_with_static_payload(# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]assert json.loads(delivery.payload.get_payload()) == {@@ -152,7 +153,7 @@ def test_payment_method_process_tokenization_with_subscription_payload(# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]assert json.loads(delivery.payload.get_payload()) == {@@ -215,7 +216,7 @@ def test_payment_method_process_tokenization_missing_correct_response_from_webho# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()assert response == PaymentMethodTokenizationResponseData(result=PaymentMethodTokenizationResult.FAILED_TO_DELIVER,@@ -269,7 +270,7 @@ def test_payment_method_process_tokenization_failure_from_app(# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]assert json.loads(delivery.payload.get_payload()) == {@@ -331,7 +332,7 @@ def test_payment_method_process_tokenization_additional_action_required(# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]assert json.loads(delivery.payload.get_payload()) == {@@ -401,7 +402,7 @@ def test_payment_method_process_tokenization_missing_required_id(# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]assert json.loads(delivery.payload.get_payload()) == {@@ -520,7 +521,7 @@ def test_expected_result_invalidates_cache_for_app(# thenmocked_request.assert_called()assert mocked_request.mock_calls[-1].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mocked_request.mock_calls[-1].args[0]assert json.loads(delivery.payload.get_payload()) == {diff --git a/saleor/plugins/webhook/tests/test_payment_webhook.py b/saleor/plugins/webhook/tests/test_payment_webhook.pyindex f4b7d9a4d2..8ef3a1eb88 100644--- a/saleor/plugins/webhook/tests/test_payment_webhook.py+++ b/saleor/plugins/webhook/tests/test_payment_webhook.py@@ -73,7 +73,7 @@ def test_trigger_webhook_sync(mock_request, payment_app):WebhookEventSyncType.PAYMENT_CAPTURE, data, payment_app.webhooks.first(), False)mock_request.assert_called_once()- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()@mock.patch(@@ -158,7 +158,7 @@ def test_send_webhook_request_sync_successful_attempt(# thenmock_clear_delivery.assert_called_once_with(event_delivery)mock_observability.assert_called_once()- # TODO (PE-371): Assert EventDeliveryAttempt DB object wasn't created+ assert not EventDeliveryAttempt.objects.exists()attempt = mock_observability.mock_calls[0].args[0]assert event_delivery.status == EventDeliveryStatus.SUCCESSdiff --git a/saleor/plugins/webhook/tests/test_shipping_webhook.py b/saleor/plugins/webhook/tests/test_shipping_webhook.pyindex 0b83c96aba..a5e5020c14 100644--- a/saleor/plugins/webhook/tests/test_shipping_webhook.py+++ b/saleor/plugins/webhook/tests/test_shipping_webhook.py@@ -5,6 +5,7 @@ from unittest.mock import callimport grapheneimport pytest+from ....core.models import EventDeliveryfrom ....graphql.tests.utils import get_graphql_contentfrom ....order import OrderStatusfrom ....webhook.const import CACHE_EXCLUDED_SHIPPING_TIME@@ -681,7 +682,7 @@ def test_trigger_webhook_sync(mock_request, shipping_app):WebhookEventSyncType.SHIPPING_LIST_METHODS_FOR_CHECKOUT, data, webhook, False)mock_request.assert_called_once()- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()@mock.patch("saleor.webhook.transport.synchronous.transport.cache.set")diff --git a/saleor/plugins/webhook/tests/test_stored_payment_method_request_delete.py b/saleor/plugins/webhook/tests/test_stored_payment_method_request_delete.pyindex 7a02cc1ff4..9c0645c11c 100644--- a/saleor/plugins/webhook/tests/test_stored_payment_method_request_delete.py+++ b/saleor/plugins/webhook/tests/test_stored_payment_method_request_delete.py@@ -4,6 +4,7 @@ from unittest import mockimport grapheneimport pytest+from ....core.models import EventDeliveryfrom ....payment.interface import (ListStoredPaymentMethodsRequestData,StoredPaymentMethodRequestDeleteData,@@ -80,7 +81,7 @@ def test_stored_payment_method_request_delete_with_static_payload(# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]assert delivery.payload.get_payload() == json.dumps(@@ -137,7 +138,7 @@ def test_stored_payment_method_request_delete_with_subscription_payload(# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]assert delivery.payload.get_payload() == json.dumps(@@ -194,7 +195,7 @@ def test_stored_payment_method_request_delete_failure_from_app(# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]assert delivery.payload.get_payload() == json.dumps(@@ -252,7 +253,7 @@ def test_stored_payment_method_request_delete_missing_response_from_webhook(# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()assert response == StoredPaymentMethodRequestDeleteResponseData(result=StoredPaymentMethodRequestDeleteResult.FAILED_TO_DELIVER,@@ -301,7 +302,7 @@ def test_stored_payment_method_request_delete_incorrect_result_response_from_web# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()assert response == StoredPaymentMethodRequestDeleteResponseData(result=StoredPaymentMethodRequestDeleteResult.FAILED_TO_DELETE,@@ -350,7 +351,7 @@ def test_stored_payment_method_request_delete_missing_result_in_response_from_we# thenmock_request.assert_called_once()assert mock_request.mock_calls[0].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()assert response == StoredPaymentMethodRequestDeleteResponseData(result=StoredPaymentMethodRequestDeleteResult.FAILED_TO_DELETE,@@ -446,7 +447,7 @@ def test_stored_payment_method_request_delete_invalidates_cache_for_app(# thenmocked_request.assert_called()assert mocked_request.mock_calls[-1].kwargs["timeout"] == WEBHOOK_SYNC_TIMEOUT- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mocked_request.mock_calls[-1].args[0]assert (diff --git a/saleor/plugins/webhook/tests/test_tax_webhook.py b/saleor/plugins/webhook/tests/test_tax_webhook.pyindex 69ebbab5b1..a99e4e210c 100644--- a/saleor/plugins/webhook/tests/test_tax_webhook.py+++ b/saleor/plugins/webhook/tests/test_tax_webhook.py@@ -7,6 +7,7 @@ from freezegun import freeze_timefrom ....checkout.fetch import fetch_checkout_info, fetch_checkout_linesfrom ....core import EventDeliveryStatus+from ....core.models import EventDeliveryfrom ....core.taxes import TaxTypefrom ....graphql.webhook.utils import get_subscription_query_hashfrom ....webhook.event_types import WebhookEventSyncType@@ -66,7 +67,7 @@ def test_get_taxes_for_order(# thenmock_request.assert_called_once()- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]assert delivery.payload.get_payload() == generate_order_payload_for_tax_calculation(@@ -184,7 +185,7 @@ def test_get_taxes_for_order_with_sync_subscription(# thenmock_request.assert_called_once()- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]assert delivery.payload.get_payload() == json.dumps(@@ -238,7 +239,7 @@ def test_get_taxes_for_checkout_with_sync_subscription(app=tax_app,)mock_request.assert_called_once()- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]assert delivery.payload.get_payload() == json.dumps(expected_payload)@@ -293,7 +294,7 @@ def test_get_taxes_for_checkout_with_sync_subscription_with_pregenerated_payload# thenmock_generate_payload.assert_not_called()mock_request.assert_called_once()- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]assert delivery.payload.get_payload() == json.dumps(expected_payload)diff --git a/saleor/plugins/webhook/tests/test_transaction_initialize_session_webhook.py b/saleor/plugins/webhook/tests/test_transaction_initialize_session_webhook.pyindex 9f53643696..3e95965417 100644--- a/saleor/plugins/webhook/tests/test_transaction_initialize_session_webhook.py+++ b/saleor/plugins/webhook/tests/test_transaction_initialize_session_webhook.py@@ -121,10 +121,8 @@ def _assert_with_static_payload(def _assert_fields(payload, webhook, expected_response, response, mock_request):webhook_app = webhook.appmock_request.assert_called_once()- # TODO (PE-371): Assert EventDelivery DB object wasn't created-+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]-assert json.loads(delivery.payload.get_payload()) == payloadassert delivery.status == EventDeliveryStatus.PENDINGassert delivery.event_type == WebhookEventSyncType.TRANSACTION_INITIALIZE_SESSIONdiff --git a/saleor/plugins/webhook/tests/test_transaction_process_session_webhook.py b/saleor/plugins/webhook/tests/test_transaction_process_session_webhook.pyindex 47f77de6b4..f289eb16a5 100644--- a/saleor/plugins/webhook/tests/test_transaction_process_session_webhook.py+++ b/saleor/plugins/webhook/tests/test_transaction_process_session_webhook.py@@ -105,10 +105,8 @@ def _assert_with_static_payload(def _assert_fields(payload, webhook, expected_response, response, mock_request):webhook_app = webhook.appmock_request.assert_called_once()- # TODO (PE-371): Assert EventDelivery DB object wasn't created-+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]-assert json.loads(delivery.payload.get_payload()) == payloadassert delivery.status == EventDeliveryStatus.PENDINGassert delivery.event_type == WebhookEventSyncType.TRANSACTION_PROCESS_SESSIONdiff --git a/saleor/webhook/tests/subscription_webhooks/test_webhook.py b/saleor/webhook/tests/subscription_webhooks/test_webhook.pyindex c0516836e4..9b83129ef1 100644--- a/saleor/webhook/tests/subscription_webhooks/test_webhook.py+++ b/saleor/webhook/tests/subscription_webhooks/test_webhook.py@@ -78,7 +78,7 @@ def test_trigger_webhook_sync_with_subscription(# thenmock_request.assert_called_once()- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]assert json.loads(delivery.payload.get_payload()) == expected_payment_payloaddiff --git a/saleor/webhook/tests/test_tax_webhook_tasks.py b/saleor/webhook/tests/test_tax_webhook_tasks.pyindex 2bf40f865a..995b957215 100644--- a/saleor/webhook/tests/test_tax_webhook_tasks.py+++ b/saleor/webhook/tests/test_tax_webhook_tasks.py@@ -3,6 +3,7 @@ from unittest import mockimport pytestfrom ...core import EventDeliveryStatus+from ...core.models import EventDeliveryfrom ..event_types import WebhookEventSyncTypefrom ..models import Webhook, WebhookEventfrom ..transport.synchronous import trigger_all_webhooks_sync@@ -55,8 +56,7 @@ def test_trigger_tax_webhook_sync(# thenmock_request.assert_called_once()- # TODO (PE-371): Assert EventDelivery DB object wasn't created-+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]assert delivery.payload.get_payload() == data@@ -83,8 +83,7 @@ def test_trigger_tax_webhook_sync_multiple_webhooks_first(# thensuccessful_webhook = tax_checkout_webhooks[0]mock_request.assert_called_once()- # TODO (PE-371): Assert EventDelivery DB object wasn't created-+ assert not EventDelivery.objects.exists()delivery = mock_request.mock_calls[0].args[0]assert delivery.payload.get_payload() == dataassert delivery.status == EventDeliveryStatus.PENDING@@ -109,7 +108,7 @@ def test_trigger_tax_webhook_sync_multiple_webhooks_last(# thenassert mock_request.call_count == 3- # TODO (PE-371): Assert EventDelivery DB object wasn't created+ assert not EventDelivery.objects.exists()for call, webhook in zip(mock_request.mock_calls, tax_checkout_webhooks):delivery = call.args[0]diff --git a/saleor/webhook/transport/synchronous/transport.py b/saleor/webhook/transport/synchronous/transport.pyindex a5710829a2..d3070c3307 100644--- a/saleor/webhook/transport/synchronous/transport.py+++ b/saleor/webhook/transport/synchronous/transport.py@@ -40,6 +40,7 @@ from ..utils import (generate_cache_key_for_webhook,get_delivery_for_webhook,handle_webhook_retry,+ save_unsuccessful_delivery_attempt,send_webhook_using_http,)@@ -107,7 +108,7 @@ def _send_webhook_request_sync(delivery.event_type,)if attempt is None:- attempt = create_attempt(delivery=delivery, task_id=None)+ attempt = create_attempt(delivery=delivery, task_id=None, with_save=False)response = WebhookResponse(content="")response_data = None@@ -155,6 +156,7 @@ def _send_webhook_request_sync(attempt_update(attempt, response)delivery_update(delivery, response.status)observability.report_event_delivery_attempt(attempt)+ save_unsuccessful_delivery_attempt(attempt)clear_successful_delivery(delivery)return response, response_data@@ -216,6 +218,7 @@ def create_delivery_for_subscription_sync_event(request=None,allow_replica=False,pregenerated_payload: Optional[dict] = None,+ with_save=True,) -> Optional[EventDelivery]:"""Generate webhook payload based on subscription query and create delivery object.@@ -265,15 +268,16 @@ def create_delivery_for_subscription_sync_event(with allow_writer():# Use transaction to ensure EventPayload and EventDelivery are created together, preventing inconsistent DB state.with transaction.atomic():- event_payload = EventPayload.objects.create_with_payload_file(- json.dumps({**data})- )- event_delivery = EventDelivery.objects.create(+ event_payload = EventPayload(payload=json.dumps({**data}))+ event_delivery = EventDelivery(status=EventDeliveryStatus.PENDING,event_type=event_type,payload=event_payload,webhook=webhook,)+ if with_save:+ event_payload.save_as_file()+ event_delivery.save()return event_delivery@@ -298,20 +302,17 @@ def trigger_webhook_sync(request=request,allow_replica=allow_replica,pregenerated_payload=pregenerated_subscription_payload,+ with_save=False,)if not delivery:return Noneelse:- with allow_writer():- # Use transaction to ensure EventPayload and EventDelivery are created together, preventing inconsistent DB state.- with transaction.atomic():- event_payload = EventPayload.objects.create_with_payload_file(payload)- delivery = EventDelivery.objects.create(- status=EventDeliveryStatus.PENDING,- event_type=event_type,- payload=event_payload,- webhook=webhook,- )+ delivery = EventDelivery(+ status=EventDeliveryStatus.PENDING,+ event_type=event_type,+ payload=EventPayload(payload=payload),+ webhook=webhook,+ )kwargs = {}if timeout:@@ -364,27 +365,20 @@ def trigger_all_webhooks_sync(request=request_context,requestor=requestor,pregenerated_payload=pregenerated_payload,+ with_save=False,)if not delivery:return Noneelse:- with allow_writer():- delivery = EventDelivery(- status=EventDeliveryStatus.PENDING,- event_type=event_type,- payload=event_payload,- webhook=webhook,- )- if event_payload is None:- # Use transaction to ensure EventPayload and EventDelivery are created together, preventing inconsistent DB state.- with transaction.atomic():- event_payload = EventPayload.objects.create_with_payload_file(- generate_payload()- )- delivery.payload = event_payload- delivery.save()- else:- delivery.save()+ if event_payload is None:+ event_payload = EventPayload(payload=generate_payload())+ delivery = EventDelivery(+ status=EventDeliveryStatus.PENDING,+ event_type=event_type,+ payload=event_payload,+ webhook=webhook,+ )+response_data = send_webhook_request_sync(delivery)if parsed_response := parse_response(response_data):return parsed_responsediff --git a/saleor/webhook/transport/utils.py b/saleor/webhook/transport/utils.pyindex 4db5613e31..12b9705271 100644--- a/saleor/webhook/transport/utils.py+++ b/saleor/webhook/transport/utils.py@@ -385,8 +385,9 @@ def catch_duration_time():def create_attempt(delivery: "EventDelivery",task_id: Optional[str] = None,+ with_save: bool = True,):- attempt = EventDeliveryAttempt.objects.create(+ attempt = EventDeliveryAttempt(delivery=delivery,task_id=task_id,duration=None,@@ -395,6 +396,8 @@ def create_attempt(response_headers=None,status=EventDeliveryStatus.PENDING,)+ if with_save:+ attempt.save()return attempt@@ -409,42 +412,62 @@ def attempt_update(attempt.response_status_code = webhook_response.response_status_codeattempt.request_headers = json.dumps(webhook_response.request_headers)attempt.status = webhook_response.status- attempt.save(- update_fields=[- "duration",- "response",- "response_headers",- "response_status_code",- "request_headers",- "status",- ]- )++ if attempt.id:+ attempt.save(+ update_fields=[+ "duration",+ "response",+ "response_headers",+ "response_status_code",+ "request_headers",+ "status",+ ]+ )@allow_writer()def clear_successful_delivery(delivery: "EventDelivery"):- if delivery.status == EventDeliveryStatus.SUCCESS:- payload_id = delivery.payload_id- delivery.delete()- if payload_id:- payloads_to_delete = EventPayload.objects.filter(- pk=payload_id, deliveries__isnull=True+ if not delivery.id or delivery.status != EventDeliveryStatus.SUCCESS:+ return++ payload_id = delivery.payload_id+ delivery.delete()+ if payload_id:+ payloads_to_delete = EventPayload.objects.filter(+ pk=payload_id, deliveries__isnull=True+ )+ files_to_delete = [+ event_payload.payload_file.name+ for event_payload in payloads_to_delete.using(+ settings.DATABASE_CONNECTION_REPLICA_NAME)- files_to_delete = [- event_payload.payload_file.name- for event_payload in payloads_to_delete.using(- settings.DATABASE_CONNECTION_REPLICA_NAME- )- if event_payload.payload_file- ]- payloads_to_delete.delete()- delete_files_from_private_storage_task(files_to_delete)+ if event_payload.payload_file+ ]+ payloads_to_delete.delete()+ delete_files_from_private_storage_task(files_to_delete)@allow_writer()def delivery_update(delivery: "EventDelivery", status: str):delivery.status = status- delivery.save(update_fields=["status"])+ if delivery.id:+ delivery.save(update_fields=["status"])+++@allow_writer()+def save_unsuccessful_delivery_attempt(attempt: "EventDeliveryAttempt"):+ delivery = attempt.delivery+ if not delivery or delivery.status == EventDeliveryStatus.SUCCESS:+ return++ event_payload = delivery.payload+ if event_payload:+ event_payload.save_as_file()++ delivery.save()+ if not attempt.id:+ attempt.save()def trigger_transaction_request(