Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix validating menu items inputs
Marcin Gębalac1b1a43ead71
diff --git a/saleor/graphql/menu/mutations.py b/saleor/graphql/menu/mutations.pyindex fe23fcc46e..a44cf129e7 100644--- a/saleor/graphql/menu/mutations.py+++ b/saleor/graphql/menu/mutations.py@@ -129,8 +129,8 @@ def _validate_menu_item_instance(cleaned_input: dict, field: str, expected_model: Model):"""Check if the value to assign as a menu item matches the expected model."""- if field in cleaned_input:- item = cleaned_input[field]+ item = cleaned_input.get(field)+ if item is not None:if not isinstance(item, expected_model):msg = (f"Enter a valid {expected_model._meta.verbose_name} ID "diff --git a/tests/api/test_menu.py b/tests/api/test_menu.pyindex b7e8809bcc..c870c9bda6 100644--- a/tests/api/test_menu.py+++ b/tests/api/test_menu.py@@ -20,6 +20,10 @@ def test_validate_menu_item_instance(category, page):with pytest.raises(ValidationError):_validate_menu_item_instance({"category": page}, "category", Category)+ # test that validation passes with empty values passed in input+ _validate_menu_item_instance({}, "category", Category)+ _validate_menu_item_instance({"category": None}, "category", Category)+def test_menu_query(user_api_client, menu):query = """