Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Stop sending regular payload to subscription webhooks (#11504)
Przemysław Łada33010c0d5f7f
diff --git a/saleor/plugins/webhook/tasks.py b/saleor/plugins/webhook/tasks.pyindex 1450d9dc9b..59620d649f 100644--- a/saleor/plugins/webhook/tasks.py+++ b/saleor/plugins/webhook/tasks.py@@ -78,6 +78,7 @@ def create_deliveries_for_subscriptions(:param event_type: event type which should be triggered.:param subscribable_object: subscribable object to process via subscription query.+ :param webhooks: sequence of async webhooks.:param requestor: used in subscription webhooks to generate meta data for payload.:return: List of event deliveries to send via webhook tasks."""@@ -186,7 +187,7 @@ def trigger_webhooks_async(payload = EventPayload.objects.create(payload=data)deliveries.extend(create_event_delivery_list_for_webhooks(- webhooks=webhooks,+ webhooks=regular_webhooks,event_payload=payload,event_type=event_type,)diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/test_webhook.py b/saleor/plugins/webhook/tests/subscription_webhooks/test_webhook.pyindex e6b5a00128..516c1098ee 100644--- a/saleor/plugins/webhook/tests/subscription_webhooks/test_webhook.py+++ b/saleor/plugins/webhook/tests/subscription_webhooks/test_webhook.py@@ -16,6 +16,26 @@ class FakeDelivery:id = TEST_ID[email protected]("saleor.plugins.webhook.tasks.send_webhook_request_async.delay")+def test_trigger_webhooks_async(+ mocked_send_webhook_request,+ webhook,+ subscription_order_created_webhook,+ order,+):+ webhook_type = WebhookEventAsyncType.ORDER_CREATED+ webhooks, payload = Webhook.objects.all(), {"example": "payload"}++ trigger_webhooks_async(payload, webhook_type, webhooks, order)++ deliveries = EventDelivery.objects.all()+ assert deliveries.count() == 2+ assert deliveries[0].webhook == subscription_order_created_webhook+ assert deliveries[1].webhook == webhook+ calls = [mock.call(deliveries[1].id), mock.call(deliveries[0].id)]+ assert mocked_send_webhook_request.mock_calls == calls++@mock.patch("saleor.plugins.webhook.tasks.send_webhook_request_async.delay")@mock.patch("saleor.plugins.webhook.tasks.create_deliveries_for_subscriptions")def test_trigger_webhooks_async_no_subscription_webhooks(diff --git a/saleor/plugins/webhook/utils.py b/saleor/plugins/webhook/utils.pyindex 16f9b506a3..1a2710473f 100644--- a/saleor/plugins/webhook/utils.py+++ b/saleor/plugins/webhook/utils.py@@ -4,9 +4,7 @@ import loggingfrom contextlib import contextmanagerfrom dataclasses import dataclassfrom time import time-from typing import TYPE_CHECKING, Any, List, Optional--from django.db.models import QuerySet+from typing import TYPE_CHECKING, Any, List, Optional, Sequencefrom ...app.models import Appfrom ...core.models import (@@ -21,6 +19,7 @@ from ...webhook.event_types import WebhookEventSyncTypeif TYPE_CHECKING:from ...payment.interface import PaymentData+ from ...webhook.models import Webhookfrom .tasks import WebhookResponseAPP_GATEWAY_ID_PREFIX = "app"@@ -187,7 +186,7 @@ def catch_duration_time():def create_event_delivery_list_for_webhooks(- webhooks: QuerySet,+ webhooks: Sequence["Webhook"],event_payload: "EventPayload",event_type: str,) -> List[EventDelivery]: