Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Increase shipping sync webhooks timeout (#13989)
Marcin Gębala64fa32c3b2a6
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 107c9f80ea..fd4bb87b08 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -51,6 +51,7 @@ All notable, unreleased changes to this project will be documented in this file.- Called after `fulfillmentUpdateTracking` or `orderFulfill` mutation if tracking number is updated.- Add support for tokenizing payment methods via sync webhooks - #13879 by @korycins- Add missing `FULFILLMENT_CREATED` event call to `automatically_fulfill_digital_lines_with_fulfillment_created` action. - #13823, by @Air-t+- Increase timeout of shipping filtering webhooks: `ORDER_FILTER_SHIPPING_METHODS` and `CHECKOUT_FILTER_SHIPPING_METHODS` to 20 seconds - #13989 by @maarcingebala### Other changesdiff --git a/saleor/plugins/webhook/const.py b/saleor/plugins/webhook/const.pyindex 001ce067d6..116becde28 100644--- a/saleor/plugins/webhook/const.py+++ b/saleor/plugins/webhook/const.py@@ -1,4 +1,3 @@CACHE_EXCLUDED_SHIPPING_KEY = "webhook_exclude_shipping_id_"CACHE_EXCLUDED_SHIPPING_TIME = 60 * 3-EXCLUDED_SHIPPING_REQUEST_TIMEOUT = 2WEBHOOK_CACHE_DEFAULT_TIMEOUT: int = 5 * 60 # 5 minutesdiff --git a/saleor/plugins/webhook/shipping.py b/saleor/plugins/webhook/shipping.pyindex e17f3e7ec5..64adc68e58 100644--- a/saleor/plugins/webhook/shipping.py+++ b/saleor/plugins/webhook/shipping.py@@ -4,6 +4,7 @@ import loggingfrom collections import defaultdictfrom typing import Any, Callable, Dict, List, Optional, Union+from django.conf import settingsfrom django.core.cache import cachefrom django.db.models import QuerySetfrom graphql import GraphQLError@@ -18,7 +19,7 @@ from ...shipping.interface import ShippingMethodDatafrom ...webhook.utils import get_webhooks_for_eventfrom ..base_plugin import ExcludedShippingMethodfrom ..const import APP_ID_PREFIX-from .const import CACHE_EXCLUDED_SHIPPING_TIME, EXCLUDED_SHIPPING_REQUEST_TIMEOUT+from .const import CACHE_EXCLUDED_SHIPPING_TIMEfrom .tasks import trigger_webhook_synclogger = logging.getLogger(__name__)@@ -117,7 +118,7 @@ def get_excluded_shipping_methods_or_fetch(payload,webhook,subscribable_object=subscribable_object,- timeout=EXCLUDED_SHIPPING_REQUEST_TIMEOUT,+ timeout=settings.WEBHOOK_SYNC_TIMEOUT,)if response_data:excluded_methods.extend(diff --git a/saleor/plugins/webhook/tests/test_shipping_webhook.py b/saleor/plugins/webhook/tests/test_shipping_webhook.pyindex 8eae405766..05ff2b7412 100644--- a/saleor/plugins/webhook/tests/test_shipping_webhook.py+++ b/saleor/plugins/webhook/tests/test_shipping_webhook.py@@ -13,11 +13,7 @@ from ....webhook.payloads import (generate_excluded_shipping_methods_for_order_payload,)from ...base_plugin import ExcludedShippingMethod-from ..const import (- CACHE_EXCLUDED_SHIPPING_KEY,- CACHE_EXCLUDED_SHIPPING_TIME,- EXCLUDED_SHIPPING_REQUEST_TIMEOUT,-)+from ..const import CACHE_EXCLUDED_SHIPPING_KEY, CACHE_EXCLUDED_SHIPPING_TIMEfrom ..shipping import get_excluded_shipping_methods_from_response, to_shipping_app_idfrom ..tasks import trigger_webhook_sync@@ -79,6 +75,7 @@ def test_excluded_shipping_methods_for_order(order_with_lines,available_shipping_methods_factory,shipping_app_factory,+ settings,):# givenshipping_app = shipping_app_factory()@@ -120,7 +117,7 @@ def test_excluded_shipping_methods_for_order(payload,shipping_app.webhooks.get(events__event_type=event_type),subscribable_object=order_with_lines,- timeout=EXCLUDED_SHIPPING_REQUEST_TIMEOUT,+ timeout=settings.WEBHOOK_SYNC_TIMEOUT,)expected_cache_key = CACHE_EXCLUDED_SHIPPING_KEY + str(order_with_lines.id)@@ -146,6 +143,7 @@ def test_multiple_app_with_excluded_shipping_methods_for_order(order_with_lines,available_shipping_methods_factory,shipping_app_factory,+ settings,):# givenshipping_app = shipping_app_factory()@@ -201,14 +199,14 @@ def test_multiple_app_with_excluded_shipping_methods_for_order(payload,shipping_app.webhooks.get(events__event_type=event_type),subscribable_object=order_with_lines,- timeout=EXCLUDED_SHIPPING_REQUEST_TIMEOUT,+ timeout=settings.WEBHOOK_SYNC_TIMEOUT,)mocked_webhook.assert_any_call(event_type,payload,second_shipping_app.webhooks.get(events__event_type=event_type),subscribable_object=order_with_lines,- timeout=EXCLUDED_SHIPPING_REQUEST_TIMEOUT,+ timeout=settings.WEBHOOK_SYNC_TIMEOUT,)expected_cache_key = CACHE_EXCLUDED_SHIPPING_KEY + str(order_with_lines.id)@@ -238,6 +236,7 @@ def test_multiple_webhooks_on_the_same_app_with_excluded_shipping_methods_for_ororder_with_lines,available_shipping_methods_factory,shipping_app_factory,+ settings,):# givenshipping_app = shipping_app_factory()@@ -307,7 +306,7 @@ def test_multiple_webhooks_on_the_same_app_with_excluded_shipping_methods_for_orpayload,webhook,subscribable_object=order_with_lines,- timeout=EXCLUDED_SHIPPING_REQUEST_TIMEOUT,+ timeout=settings.WEBHOOK_SYNC_TIMEOUT,)expected_cache_key = CACHE_EXCLUDED_SHIPPING_KEY + str(order_with_lines.id)@@ -535,6 +534,7 @@ def test_excluded_shipping_methods_for_checkout_webhook(checkout_with_items,available_shipping_methods_factory,shipping_app_factory,+ settings,):# givenshipping_app = shipping_app_factory()@@ -575,7 +575,7 @@ def test_excluded_shipping_methods_for_checkout_webhook(payload,shipping_app.webhooks.get(events__event_type=event_type),subscribable_object=checkout_with_items,- timeout=EXCLUDED_SHIPPING_REQUEST_TIMEOUT,+ timeout=settings.WEBHOOK_SYNC_TIMEOUT,)expected_cache_key = CACHE_EXCLUDED_SHIPPING_KEY + str(checkout_with_items.token)@@ -648,6 +648,7 @@ def test_multiple_app_with_excluded_shipping_methods_for_checkout(checkout_with_items,available_shipping_methods_factory,shipping_app_factory,+ settings,):# givenshipping_app = shipping_app_factory()@@ -702,14 +703,14 @@ def test_multiple_app_with_excluded_shipping_methods_for_checkout(payload,shipping_app.webhooks.get(events__event_type=event_type),subscribable_object=checkout_with_items,- timeout=EXCLUDED_SHIPPING_REQUEST_TIMEOUT,+ timeout=settings.WEBHOOK_SYNC_TIMEOUT,)mocked_webhook.assert_any_call(event_type,payload,second_shipping_app.webhooks.get(events__event_type=event_type),subscribable_object=checkout_with_items,- timeout=EXCLUDED_SHIPPING_REQUEST_TIMEOUT,+ timeout=settings.WEBHOOK_SYNC_TIMEOUT,)expected_cache_key = CACHE_EXCLUDED_SHIPPING_KEY + str(checkout_with_items.token)@@ -741,6 +742,7 @@ def test_multiple_webhooks_on_the_same_app_with_excluded_shipping_methods_for_chcheckout_with_items,available_shipping_methods_factory,shipping_app_factory,+ settings,):# givenshipping_app = shipping_app_factory()@@ -809,7 +811,7 @@ def test_multiple_webhooks_on_the_same_app_with_excluded_shipping_methods_for_chpayload,webhook,subscribable_object=checkout_with_items,- timeout=EXCLUDED_SHIPPING_REQUEST_TIMEOUT,+ timeout=settings.WEBHOOK_SYNC_TIMEOUT,)expected_cache_key = CACHE_EXCLUDED_SHIPPING_KEY + str(checkout_with_items.token)