Skip to content

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

Fix weight scalar with 0 value

fowczrek3a888ad377d6
diff --git a/saleor/graphql/core/scalars.py b/saleor/graphql/core/scalars.py
index dbd5e94f17..45f247ff77 100644
--- a/saleor/graphql/core/scalars.py
+++ b/saleor/graphql/core/scalars.py
@@ -1,8 +1,8 @@
import decimal
import graphene
-from graphql.language import ast
from graphql.error import GraphQLError
+from graphql.language import ast
from measurement.measures import Weight
from ...core.weight import convert_weight, get_default_weight_unit
@@ -41,7 +41,7 @@ class WeightScalar(graphene.Scalar):
weight = Weight(**{value["unit"]: value["value"]})
else:
weight = WeightScalar.parse_decimal(value)
- if not weight:
+ if weight is None:
raise GraphQLError(f"Unsupported value: {value}")
return weight
@@ -61,7 +61,7 @@ class WeightScalar(graphene.Scalar):
weight = WeightScalar.parse_literal_object(node)
else:
weight = WeightScalar.parse_decimal(node.value)
- if not weight:
+ if weight is None:
raise GraphQLError(f"Unsupported value: {node.value}")
return weight
diff --git a/tests/api/test_product.py b/tests/api/test_product.py
index 766d5e6ede..d62c9a29d3 100644
--- a/tests/api/test_product.py
+++ b/tests/api/test_product.py
@@ -4004,6 +4004,8 @@ mutation createProduct(
@pytest.mark.parametrize(
"weight, expected_weight_value, expected_weight_unit",
(
+ ("0", 0, "kg"),
+ (0, 0, "kg"),
(11.11, 11.11, "kg"),
(11, 11.0, "kg"),
("11.11", 11.11, "kg"),
@@ -4047,6 +4049,8 @@ def test_create_product_with_weight_variable(
@pytest.mark.parametrize(
"weight, expected_weight_value, expected_weight_unit",
(
+ ("0", 0, "kg"),
+ (0, 0, "kg"),
("11.11", 11.11, "kg"),
("11", 11.0, "kg"),
('"11.11"', 11.11, "kg"),