Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
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.pyindex be1caa6046..e1f167b0af 100644--- a/saleor/graphql/core/scalars.py+++ b/saleor/graphql/core/scalars.py@@ -96,6 +96,8 @@ class WeightScalar(graphene.Scalar):@staticmethoddef parse_value(value):if isinstance(value, dict):+ if value.get("value") is None:+ return Noneweight = 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.pynew file mode 100644index 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