Skip to content

Commit

Permalink
Merge pull request #4561 from mirumee/fix-validating-menu-items
Browse files Browse the repository at this point in the history
Fix validating menu items inputs
  • Loading branch information
maarcingebala committed Jul 30, 2019
2 parents d9a4ecb + c1b1a43 commit 94314bf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions saleor/graphql/menu/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
4 changes: 4 additions & 0 deletions tests/api/test_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand Down

0 comments on commit 94314bf

Please sign in to comment.