Skip to content

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

Fix missing validation for weight values in WeightScalar (#19258)

Md Mushfiqur Rahim9911e61ee066
diff --git a/saleor/graphql/core/scalars.py b/saleor/graphql/core/scalars.py
index be1caa6046..e1f167b0af 100644
--- a/saleor/graphql/core/scalars.py
+++ b/saleor/graphql/core/scalars.py
@@ -96,6 +96,8 @@ class WeightScalar(graphene.Scalar):
@staticmethod
def parse_value(value):
if isinstance(value, dict):
+ if value.get("value") is None:
+ return None
weight = Weight(**{value["unit"]: value["value"]})
else:
weight = WeightScalar.parse_decimal(value)
diff --git a/saleor/graphql/core/tests/test_scalars_weight.py b/saleor/graphql/core/tests/test_scalars_weight.py
new file mode 100644
index 0000000000..8946b52c0b
--- /dev/null
+++ b/saleor/graphql/core/tests/test_scalars_weight.py
@@ -0,0 +1,17 @@
+import pytest
+
+from ..scalars import WeightScalar
+
+
+ "value",
+ [
+ {"unit": "kg", "value": None},
+ {"unit": "g", "value": None},
+ {"unit": "lb", "value": None},
+ {"unit": "oz", "value": None},
+ ],
+)
+def test_weight_scalar_parse_value_with_none_value(value):
+ result = WeightScalar.parse_value(value)
+ assert result is None