Skip to content

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

Fix thumbnails size key error main (#11775)

Jakub91a7634f0608
diff --git a/saleor/order/notifications.py b/saleor/order/notifications.py
index 47ec95566c..3b64a007f7 100644
--- a/saleor/order/notifications.py
+++ b/saleor/order/notifications.py
@@ -27,7 +27,9 @@ def get_image_payload(instance: ProductMedia):
# This is temporary solution, the get_product_image_thumbnail_url
# should be optimize - we should fetch all thumbnails at once instead of
# fetching thumbnails by one for each size
- size: get_image_or_proxy_url(None, str(instance.id), "ProductMedia", size, None)
+ str(size): get_image_or_proxy_url(
+ None, str(instance.id), "ProductMedia", size, None
+ )
for size in THUMBNAIL_SIZES
}
diff --git a/saleor/order/tests/test_notifications.py b/saleor/order/tests/test_notifications.py
index 976c7144bb..a0a3ca15c8 100644
--- a/saleor/order/tests/test_notifications.py
+++ b/saleor/order/tests/test_notifications.py
@@ -678,4 +678,4 @@ def test_get_default_images_payload(product_with_image):
# then
images_payload = payload["first_image"]["original"]
for th_size in THUMBNAIL_SIZES:
- assert images_payload[th_size] == f"/thumbnail/{media_id}/{th_size}/"
+ assert images_payload[str(th_size)] == f"/thumbnail/{media_id}/{th_size}/"
diff --git a/saleor/plugins/email_common.py b/saleor/plugins/email_common.py
index 2cbdd45f35..2e88742f15 100644
--- a/saleor/plugins/email_common.py
+++ b/saleor/plugins/email_common.py
@@ -145,7 +145,7 @@ def format_datetime(this, date, date_format=None):
def get_product_image_thumbnail(this, size, image_data):
"""Use provided size to get a correct image."""
expected_size = get_thumbnail_size(size)
- return image_data["original"][expected_size]
+ return image_data["original"][str(expected_size)]
def compare(this, val1, compare_operator, val2):
diff --git a/saleor/plugins/tests/test_email_common.py b/saleor/plugins/tests/test_email_common.py
index b72bf6e234..7036e3767d 100644
--- a/saleor/plugins/tests/test_email_common.py
+++ b/saleor/plugins/tests/test_email_common.py
@@ -1,3 +1,4 @@
+import json
from unittest.mock import patch
import pytest
@@ -71,4 +72,16 @@ def test_get_product_image_thumbnail(product_with_image):
thumbnail = get_product_image_thumbnail(None, 100, image_data)
# then
- assert thumbnail == image_data["original"][128]
+ assert thumbnail == image_data["original"]["128"]
+
+
+def test_get_product_image_thumbnail_simulate_json_dump_and_load(product_with_image):
+ # given
+ image_data = {"original": get_image_payload(product_with_image.media.first())}
+ image_data = json.dumps(image_data)
+ image_data = json.loads(image_data)
+ # when
+ thumbnail = get_product_image_thumbnail(None, 100, image_data)
+
+ # then
+ assert thumbnail == image_data["original"]["128"]