Skip to content

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

Use fields default value if no value is provided and field is not null

Pacu2e167cdf6a5e0
diff --git a/saleor/graphql/core/mutations.py b/saleor/graphql/core/mutations.py
index 43c6fcc492..41c0decf3e 100644
--- a/saleor/graphql/core/mutations.py
+++ b/saleor/graphql/core/mutations.py
@@ -211,11 +211,13 @@ class ModelMutation(BaseMutation):
opts = instance._meta
for f in opts.fields:
- if not f.editable or isinstance(
- f, models.AutoField) or f.name not in cleaned_data:
+ if any([not f.editable, isinstance(f, models.AutoField),
+ f.name not in cleaned_data]):
continue
- else:
- f.save_form_data(instance, cleaned_data[f.name])
+ data = cleaned_data[f.name]
+ if not f.null and data is None:
+ data = f._get_default()
+ f.save_form_data(instance, data)
return instance
@classmethod
diff --git a/tests/api/test_product.py b/tests/api/test_product.py
index 300b100812..b0f2d7b125 100644
--- a/tests/api/test_product.py
+++ b/tests/api/test_product.py
@@ -10,7 +10,6 @@ from prices import Money
from tests.utils import (
create_image, create_pdf_file_with_image_ext, get_graphql_content)
-from saleor.core import TaxRateType
from saleor.graphql.product.utils import update_variants_names
from saleor.product.models import (
Category, Collection, Product, ProductImage, ProductType, ProductVariant)