Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix error on saving variant attributes with has_variants disabled
Pacu2ce33b92ba109
diff --git a/saleor/dashboard/product/forms.py b/saleor/dashboard/product/forms.pyindex ca2cc1aa88..eb53ec0cc4 100644--- a/saleor/dashboard/product/forms.py+++ b/saleor/dashboard/product/forms.py@@ -94,14 +94,13 @@ class ProductTypeForm(forms.ModelForm):return dataself.check_if_variants_changed(has_variants)- self.update_variants_names(data)+ self.update_variants_names(saved_attributes=variant_attr)return data- def update_variants_names(self, data):+ def update_variants_names(self, saved_attributes):# Some variant attributes could be removed so name should be updated# accordinglyinitial_attributes = set(self.instance.variant_attributes.all())- saved_attributes = set(data.get('variant_attributes', []))attributes_changed = initial_attributes.intersection(saved_attributes)if not attributes_changed:returndiff --git a/tests/dashboard/test_product.py b/tests/dashboard/test_product.pyindex 0e1cc48dcd..3e434a27fc 100644--- a/tests/dashboard/test_product.py+++ b/tests/dashboard/test_product.py@@ -60,6 +60,19 @@ def test_valid_product_type_form(color_attribute, size_attribute):assert not form.is_valid()+def test_product_type_form_missing_variant_attributes(+ color_attribute, size_attribute, product_type):+ product_type.has_variants = True+ product_type.save()+ data = {+ 'name': "Testing Type",+ 'product_attributes': [color_attribute.pk],+ 'variant_attributes': [size_attribute.pk],+ 'has_variants': False}+ form = ProductTypeForm(data, instance=product_type)+ assert not form.is_valid()++def test_variantless_product_type_form(color_attribute, size_attribute):data = {'name': "Testing Type",