Skip to content

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

Handle None as attribute value - raise validation error

IKarbowiak63cdc145cfca
diff --git a/saleor/graphql/product/tests/test_variant.py b/saleor/graphql/product/tests/test_variant.py
index 8f8cd9d77f..0b367a32fa 100644
--- a/saleor/graphql/product/tests/test_variant.py
+++ b/saleor/graphql/product/tests/test_variant.py
@@ -819,6 +819,7 @@ def test_update_product_variant_with_duplicated_attribute(
([], "size expects a value but none were given"),
(["one", "two"], "A variant attribute cannot take more than one value"),
([" "], "Attribute values cannot be blank"),
+ ([None], "Attribute values cannot be blank"),
),
)
def test_update_product_variant_requires_values(
@@ -828,6 +829,7 @@ def test_update_product_variant_requires_values(
- No values
- Blank value
+ - None as value
- More than one value
"""
diff --git a/saleor/graphql/product/utils.py b/saleor/graphql/product/utils.py
index 3f5d09130d..992c23fe4e 100644
--- a/saleor/graphql/product/utils.py
+++ b/saleor/graphql/product/utils.py
@@ -50,7 +50,7 @@ def validate_attribute_input_for_variant(instance: "Attribute", values: List[str
code=ProductErrorCode.INVALID.value,
)
- if not values[0].strip():
+ if values[0] is None or not values[0].strip():
raise ValidationError(
"Attribute values cannot be blank", code=ProductErrorCode.REQUIRED.value
)