Repository: saleor/saleor

Issue:
Error while trying to disable variants for product type
### Steps to reproduce the problem

1. Choose a product type with variant attributes in the dashboard
2. Uncheck "Enable variants" indicator

### What I expected to happen
Disabled variants for product type or proper warning similar to "Some products of this type have more than one variant"

### What happened instead/how it failed
```
Traceback:

File "/home/adam/mirumee/saleor/.direnv/python-3.6.4/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  35.             response = get_response(request)

File "/home/adam/mirumee/saleor/.direnv/python-3.6.4/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  128.                 response = self.process_exception_by_middleware(e, request)

File "/home/adam/mirumee/saleor/.direnv/python-3.6.4/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  126.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/adam/mirumee/saleor/.direnv/python-3.6.4/lib/python3.6/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  21.                 return view_func(request, *args, **kwargs)

File "/home/adam/mirumee/saleor/.direnv/python-3.6.4/lib/python3.6/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  21.                 return view_func(request, *args, **kwargs)

File "/home/adam/mirumee/saleor/saleor/dashboard/product/views.py" in product_type_edit
  74.     if form.is_valid():

File "/home/adam/mirumee/saleor/.direnv/python-3.6.4/lib/python3.6/site-packages/django/forms/forms.py" in is_valid
  179.         return self.is_bound and not self.errors

File "/home/adam/mirumee/saleor/.direnv/python-3.6.4/lib/python3.6/site-packages/django/forms/forms.py" in errors
  174.             self.full_clean()

File "/home/adam/mirumee/saleor/.direnv/python-3.6.4/lib/python3.6/site-packages/django/forms/forms.py" in full_clean
  377.         self._clean_form()

File "/home/adam/mirumee/saleor/.direnv/python-3.6.4/lib/python3.6/site-packages/django/forms/forms.py" in _clean_form
  404.             cleaned_data = self.clean()

File "/home/adam/mirumee/saleor/saleor/dashboard/product/forms.py" in clean
  97.         self.update_variants_names(data)

File "/home/adam/mirumee/saleor/saleor/dashboard/product/forms.py" in update_variants_names
  104.         saved_attributes = set(list(data.get('variant_attributes')))

Exception Type: TypeError at /dashboard/products/types/3/update/
Exception Value: 'NoneType' object is not iterable
```


```
data | {'is_shipping_required': True,  'name': 'Coffee',  'product_attributes': <QuerySet [<ProductAttribute: Brand>, <ProductAttribute: Coffee Genre>]>}
initial_attributes | set()
self | <ProductTypeForm bound=True, valid=False, fields=(name;has_variants;product_attributes;variant_attributes;is_shipping_required)>
```
It seems that 
```saved_attributes = set(list(data.get('variant_attributes')))```
crashes at trying creating list from `None`.
Possibly related with #2026




Discussion:
Slightly offtopic: why `set(list(...))`?

Resolving patch:
diff --git a/saleor/dashboard/product/forms.py b/saleor/dashboard/product/forms.py
--- a/saleor/dashboard/product/forms.py
+++ b/saleor/dashboard/product/forms.py
@@ -94,14 +94,13 @@ def clean(self):
             return data
 
         self.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
         # accordingly
-        initial_attributes = set(list(self.instance.variant_attributes.all()))
-        saved_attributes = set(list(data.get('variant_attributes')))
+        initial_attributes = set(self.instance.variant_attributes.all())
         attributes_changed = initial_attributes.intersection(saved_attributes)
         if not attributes_changed:
             return


Test patch:
diff --git a/tests/dashboard/test_product.py b/tests/dashboard/test_product.py
--- 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",