Skip to content

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

Wrap notify webhook with json.dumps

Maciej Korycinski6ec0c22ac02a
diff --git a/saleor/plugins/webhook/plugin.py b/saleor/plugins/webhook/plugin.py
index 290910f736..c3692df1fc 100644
--- a/saleor/plugins/webhook/plugin.py
+++ b/saleor/plugins/webhook/plugin.py
@@ -1,5 +1,7 @@
+import json
from typing import TYPE_CHECKING, Any, Optional
+from ...core.utils.json_serializer import CustomJsonEncoder
from ...webhook.event_types import WebhookEventType
from ...webhook.payloads import (
generate_checkout_payload,
@@ -151,4 +153,6 @@ class WebhookPlugin(BasePlugin):
if not self.active:
return previous_value
data = {"notify_event": event, "payload": payload}
- trigger_webhooks_for_event.delay(WebhookEventType.NOTIFY_USER, data)
+ trigger_webhooks_for_event.delay(
+ WebhookEventType.NOTIFY_USER, json.dumps(data, cls=CustomJsonEncoder)
+ )
diff --git a/saleor/plugins/webhook/tests/test_webhook.py b/saleor/plugins/webhook/tests/test_webhook.py
index 2e57c71938..e91fb569f2 100644
--- a/saleor/plugins/webhook/tests/test_webhook.py
+++ b/saleor/plugins/webhook/tests/test_webhook.py
@@ -1,3 +1,4 @@
+import json
from unittest import mock
from urllib.parse import urlencode
@@ -12,6 +13,7 @@ from ....account.notifications import (
from ....app.models import App
from ....core.notifications import get_site_context
from ....core.notify_events import NotifyEventType
+from ....core.utils.json_serializer import CustomJsonEncoder
from ....core.utils.url import prepare_url
from ....webhook.event_types import WebhookEventType
from ....webhook.payloads import (
@@ -281,5 +283,5 @@ def test_notify_user(mocked_webhook_trigger, settings, customer_user):
"payload": payload,
}
mocked_webhook_trigger.assert_called_once_with(
- WebhookEventType.NOTIFY_USER, expected_data
+ WebhookEventType.NOTIFY_USER, json.dumps(expected_data, cls=CustomJsonEncoder)
)