Skip to content

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

Stop sending regular payload to subscription webhooks (#11504)

Przemysław Łada33010c0d5f7f
diff --git a/saleor/plugins/webhook/tasks.py b/saleor/plugins/webhook/tasks.py
index 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.py
index 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.py
index 16f9b506a3..1a2710473f 100644
--- a/saleor/plugins/webhook/utils.py
+++ b/saleor/plugins/webhook/utils.py
@@ -4,9 +4,7 @@ import logging
from contextlib import contextmanager
from dataclasses import dataclass
from 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, Sequence
from ...app.models import App
from ...core.models import (
@@ -21,6 +19,7 @@ from ...webhook.event_types import WebhookEventSyncType
if TYPE_CHECKING:
from ...payment.interface import PaymentData
+ from ...webhook.models import Webhook
from .tasks import WebhookResponse
APP_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]: