Skip to content

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

Add exception handler in Update Product mutation for collection with empty ID (#7629)

Dawid Matuszczyk80eabc010dc7
diff --git a/saleor/graphql/product/tests/test_product.py b/saleor/graphql/product/tests/test_product.py
index 7e611fcfb0..ecd83ebecd 100644
--- a/saleor/graphql/product/tests/test_product.py
+++ b/saleor/graphql/product/tests/test_product.py
@@ -5544,6 +5544,42 @@ def test_update_product_with_page_reference_attribute_value(
assert product_type_page_reference_attribute.values.count() == values_count + 1
+def test_update_product_with_empty_input_collections(
+ product, permission_manage_products, staff_api_client
+):
+ # given
+ query = """
+ mutation updateProduct($productId: ID!, $input: ProductInput!) {
+ productUpdate(id: $productId, input: $input) {
+ productErrors {
+ field
+ message
+ code
+ }
+ product {
+ id
+ }
+ }
+ }
+
+ """
+ product_id = graphene.Node.to_global_id("Product", product.pk)
+ variables = {
+ "productId": product_id,
+ "input": {"collections": [""]},
+ }
+ # when
+ response = staff_api_client.post_graphql(
+ query, variables, permissions=[permission_manage_products]
+ )
+ # then
+ content = get_graphql_content(response)
+ data = content["data"]["productUpdate"]
+ assert len(data["productErrors"]) == 1
+ product_errors = data["productErrors"][0]
+ assert product_errors["code"] == ProductErrorCode.GRAPHQL_ERROR.name
+
+
@patch("saleor.plugins.manager.PluginsManager.product_updated")
def test_update_product_with_page_reference_attribute_existing_value(
updated_webhook_mock,
diff --git a/saleor/graphql/utils/__init__.py b/saleor/graphql/utils/__init__.py
index 7e80851a41..78e94dfd08 100644
--- a/saleor/graphql/utils/__init__.py
+++ b/saleor/graphql/utils/__init__.py
@@ -35,6 +35,7 @@ def resolve_global_ids_to_primary_keys(
for graphql_id in ids:
if not graphql_id:
+ invalid_ids.append(graphql_id)
continue
try: