Skip to content

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

Reduce number of queries of getting attributes display

Marcin Gębalaab0141d4ea11
diff --git a/saleor/product/utils.py b/saleor/product/utils.py
index e6323047fe..105b51b590 100644
--- a/saleor/product/utils.py
+++ b/saleor/product/utils.py
@@ -1,17 +1,14 @@
-from django.core.exceptions import ObjectDoesNotExist
-
-
def get_attributes_display(variant, attributes):
display = {}
for attribute in attributes:
value = variant.get_attribute(attribute.pk)
if value:
- try:
- choice = attribute.values.get(pk=value)
- except ObjectDoesNotExist:
- pass
- except ValueError:
- display[attribute.pk] = value
+ choices = attribute.values.all()
+ if choices:
+ for choice in attribute.values.all():
+ if choice.pk == value:
+ display[attribute.pk] = choice
+ break
else:
- display[attribute.pk] = choice
+ display[attribute.pk] = value
return display