Repository: saleor/saleor

Issue:
Increase timeout of sync shipping method filtering webhooks
The following sync webhooks currently use 2s timeout:
- `ORDER_FILTER_SHIPPING_METHODS` 
- `CHECKOUT_FILTER_SHIPPING_METHODS`

There are no reasons to make the timout shorter than other webhooks. Other sync webhooks use `settings.WEBHOOK_SYNC_TIMEOUT` which should be used for these two for consistency.


Discussion:

Resolving patch:
diff --git a/saleor/plugins/webhook/const.py b/saleor/plugins/webhook/const.py
--- 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 = 2
 WEBHOOK_CACHE_DEFAULT_TIMEOUT: int = 5 * 60  # 5 minutes
diff --git a/saleor/plugins/webhook/shipping.py b/saleor/plugins/webhook/shipping.py
--- a/saleor/plugins/webhook/shipping.py
+++ b/saleor/plugins/webhook/shipping.py
@@ -4,6 +4,7 @@
 from collections import defaultdict
 from typing import Any, Callable, Dict, List, Optional, Union
 
+from django.conf import settings
 from django.core.cache import cache
 from django.db.models import QuerySet
 from graphql import GraphQLError
@@ -18,7 +19,7 @@
 from ...webhook.utils import get_webhooks_for_event
 from ..base_plugin import ExcludedShippingMethod
 from ..const import APP_ID_PREFIX
-from .const import CACHE_EXCLUDED_SHIPPING_TIME, EXCLUDED_SHIPPING_REQUEST_TIMEOUT
+from .const import CACHE_EXCLUDED_SHIPPING_TIME
 from .tasks import trigger_webhook_sync
 
 logger = 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(


Test patch:
diff --git a/saleor/plugins/webhook/tests/test_shipping_webhook.py b/saleor/plugins/webhook/tests/test_shipping_webhook.py
--- a/saleor/plugins/webhook/tests/test_shipping_webhook.py
+++ b/saleor/plugins/webhook/tests/test_shipping_webhook.py
@@ -13,11 +13,7 @@
     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_TIME
 from ..shipping import get_excluded_shipping_methods_from_response, to_shipping_app_id
 from ..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,
 ):
     # given
     shipping_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,
 ):
     # given
     shipping_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_or
     order_with_lines,
     available_shipping_methods_factory,
     shipping_app_factory,
+    settings,
 ):
     # given
     shipping_app = shipping_app_factory()
@@ -307,7 +306,7 @@ def test_multiple_webhooks_on_the_same_app_with_excluded_shipping_methods_for_or
             payload,
             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,
 ):
     # given
     shipping_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,
 ):
     # given
     shipping_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_ch
     checkout_with_items,
     available_shipping_methods_factory,
     shipping_app_factory,
+    settings,
 ):
     # given
     shipping_app = shipping_app_factory()
@@ -809,7 +811,7 @@ def test_multiple_webhooks_on_the_same_app_with_excluded_shipping_methods_for_ch
             payload,
             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)