Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
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.pyindex 43c6fcc492..41c0decf3e 100644--- a/saleor/graphql/core/mutations.py+++ b/saleor/graphql/core/mutations.py@@ -211,11 +211,13 @@ class ModelMutation(BaseMutation):opts = instance._metafor 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@classmethoddiff --git a/tests/api/test_product.py b/tests/api/test_product.pyindex 300b100812..b0f2d7b125 100644--- a/tests/api/test_product.py+++ b/tests/api/test_product.py@@ -10,7 +10,6 @@ from prices import Moneyfrom tests.utils import (create_image, create_pdf_file_with_image_ext, get_graphql_content)-from saleor.core import TaxRateTypefrom saleor.graphql.product.utils import update_variants_namesfrom saleor.product.models import (Category, Collection, Product, ProductImage, ProductType, ProductVariant)