Skip to content

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

Update condition and comment in validate_slug_and_generate_if_needed

IKarbowiakbfb27939924e
diff --git a/saleor/graphql/core/utils/__init__.py b/saleor/graphql/core/utils/__init__.py
index efb404ef9e..68884292f4 100644
--- a/saleor/graphql/core/utils/__init__.py
+++ b/saleor/graphql/core/utils/__init__.py
@@ -77,8 +77,10 @@ def validate_slug_and_generate_if_needed(
slug_field_name: str = "slug",
) -> dict:
"""Validate slug from input and generate in create mutation if is not given."""
- # update mutation - just check if value is not empty
- if getattr(instance, slug_field_name):
+ # update mutation - just check if slug value is not empty
+ # we use _state.adding to checking if instance is saved because if pk has default
+ # value it is set before save
+ if not instance._state.adding: # type: ignore
validate_slug_value(cleaned_input)
return cleaned_input