Skip to content

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

Allow adding variant attributes if has_variants is False

Marcin Gębala32aecf3c529f
diff --git a/saleor/graphql/product/mutations/attributes.py b/saleor/graphql/product/mutations/attributes.py
index ebbab74605..d49828ee71 100644
--- a/saleor/graphql/product/mutations/attributes.py
+++ b/saleor/graphql/product/mutations/attributes.py
@@ -121,17 +121,6 @@ class AttributeCreate(AttributeMixin, ModelMutation):
description = 'Creates an attribute.'
model = models.Attribute
- @classmethod
- def clean_product_type_variant_attributes(
- cls, product_type, type, errors):
- if (type == AttributeTypeEnum.VARIANT.name
- and not product_type.has_variants):
- cls.add_error(
- errors, 'product_type',
- 'Cannot create an Attribute for ProductType'
- 'not supporting ProductVariants.')
- return errors
-
@classmethod
@permission_required('product.manage_products')
def mutate(cls, root, info, id, type, input):
@@ -145,8 +134,6 @@ class AttributeCreate(AttributeMixin, ModelMutation):
cleaned_input = cls.clean_input(info, instance, input, errors)
instance = cls.construct_instance(instance, cleaned_input)
cls.clean_instance(instance, errors)
- cls.clean_product_type_variant_attributes(
- product_type, type, errors)
if errors:
return AttributeCreate(errors=errors)
diff --git a/tests/api/test_attributes.py b/tests/api/test_attributes.py
index edd8ae6a2f..1ee3bbc611 100644
--- a/tests/api/test_attributes.py
+++ b/tests/api/test_attributes.py
@@ -169,25 +169,6 @@ def test_create_attribute_and_attribute_values_errors(
assert errors[0]['message'] == error_msg
-def test_create_variant_attribute_for_product_type_without_variants(
- staff_api_client, permission_manage_products, product_type):
- assert not product_type.has_variants
- query = CREATE_ATTRIBUTES_QUERY
- id = graphene.Node.to_global_id('ProductType', product_type.id)
-
- variables = {
- 'name': 'Example name', 'id': id,
- 'type': AttributeTypeEnum.VARIANT.name, 'values': []}
- response = staff_api_client.post_graphql(
- query, variables, permissions=[permission_manage_products])
- content = get_graphql_content(response)
- errors = content['data']['attributeCreate']['errors']
- assert errors[0]['field'] == 'productType'
- assert errors[0]['message'] == (
- 'Cannot create an Attribute for ProductType'
- 'not supporting ProductVariants.')
-
-
def test_create_variant_attribute(
staff_api_client, permission_manage_products, product_type):
product_type.has_variants = True