Skip to content

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

Treat certains exceptions as expected, avoid spilling expected errors to (#18977)

Marcin Wcisłocd881afafefd
diff --git a/saleor/product/tasks.py b/saleor/product/tasks.py
index 3d96ce1a76..03997d21a9 100644
--- a/saleor/product/tasks.py
+++ b/saleor/product/tasks.py
@@ -378,6 +378,10 @@ def on_failure_fetch_product_media_image_task(self, exc, task_id, args, kwargs,
default_retry_delay=1,
autoretry_for=(IOError,),
on_failure=on_failure_fetch_product_media_image_task,
+ throws=(
+ IOError,
+ ValueError,
+ ),
)
@allow_writer()
def fetch_product_media_image_task(product_media_id: int):
diff --git a/saleor/product/tests/test_tasks.py b/saleor/product/tests/test_tasks.py
index e6fe6b816f..9ffe71973e 100644
--- a/saleor/product/tests/test_tasks.py
+++ b/saleor/product/tests/test_tasks.py
@@ -502,7 +502,9 @@ def test_fetch_product_media_image_request_exception(
assert ProductMedia.objects.filter(pk=product_media.pk).exists()
-def test_fetch_product_media_image_invalid_schema_exception(
[email protected]("exc_class", [InvalidSchema, ValueError])
+def test_fetch_product_media_image_non_retryable_exception(
+ exc_class,
product_media_image_not_yet_fetched,
):
# given
@@ -512,8 +514,8 @@ def test_fetch_product_media_image_invalid_schema_exception(
# when
with patch("saleor.product.tasks.HTTPClient") as mock_http_client:
- mock_http_client.send_request.side_effect = InvalidSchema()
- with pytest.raises(InvalidSchema):
+ mock_http_client.send_request.side_effect = exc_class()
+ with pytest.raises(exc_class):
# this call simulates a single attempt for executing the task
fetch_product_media_image_task(product_media.pk)
@@ -521,7 +523,9 @@ def test_fetch_product_media_image_invalid_schema_exception(
assert ProductMedia.objects.filter(pk=product_media.pk).exists()
-def test_fetch_product_media_image_invalid_schema_exception_on_failure_handler(
[email protected]("exc_class", [InvalidSchema, ValueError])
+def test_fetch_product_media_image_non_retryable_exception_on_failure_handler(
+ exc_class,
product_media_image_not_yet_fetched,
):
# given
@@ -531,7 +535,7 @@ def test_fetch_product_media_image_invalid_schema_exception_on_failure_handler(
# when
with patch("saleor.product.tasks.HTTPClient") as mock_http_client:
- mock_http_client.send_request.side_effect = InvalidSchema()
+ mock_http_client.send_request.side_effect = exc_class()
fetch_product_media_image_task.apply(args=(product_media.pk,))
# then