Skip to content

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

Fix mypy errors for graphql.product

IKarbowiak470f9a39ff4d
diff --git a/saleor/graphql/product/mutations/attributes.py b/saleor/graphql/product/mutations/attributes.py
index 1cd83224ef..0b1484eebc 100644
--- a/saleor/graphql/product/mutations/attributes.py
+++ b/saleor/graphql/product/mutations/attributes.py
@@ -421,13 +421,13 @@ class AttributeAssign(BaseMutation):
@classmethod
@transaction.atomic()
- def perform_mutation(
- cls, _root, info, product_type_id: str, operations: List[AttributeAssignInput]
- ):
+ def perform_mutation(cls, _root, info, **data):
+ product_type_id: str = data["product_type_id"]
+ operations: List[AttributeAssignInput] = data["operations"]
# Retrieve the requested product type
- product_type = graphene.Node.get_node_from_global_id(
+ product_type: models.ProductType = graphene.Node.get_node_from_global_id(
info, product_type_id, only_type=ProductType
- ) # type: models.ProductType
+ )
# Resolve all the passed IDs to ints
product_attrs_pks, variant_attrs_pks = cls.get_operations(info, operations)
@@ -437,7 +437,7 @@ class AttributeAssign(BaseMutation):
{
"operations": ValidationError(
"Variants are disabled in this product type.",
- code=ProductErrorCode.ATTRIBUTE_VARIANTS_DISABLED,
+ code=ProductErrorCode.ATTRIBUTE_VARIANTS_DISABLED.value,
)
}
)
@@ -481,9 +481,9 @@ class AttributeUnassign(BaseMutation):
getattr(product_type, field).remove(*pks)
@classmethod
- def perform_mutation(
- cls, _root, info, product_type_id: str, attribute_ids: List[str]
- ):
+ def perform_mutation(cls, _root, info, **data):
+ product_type_id: str = data["product_type_id"]
+ attribute_ids: List[str] = data["attribute_ids"]
# Retrieve the requested product type
product_type = graphene.Node.get_node_from_global_id(
info, product_type_id, only_type=ProductType
@@ -564,7 +564,7 @@ def validate_value_is_unique(attribute: models.Attribute, value: models.Attribut
{
"name": ValidationError(
f"Value with slug {value.slug} already exists.",
- code=ProductErrorCode.ALREADY_EXISTS,
+ code=ProductErrorCode.ALREADY_EXISTS.value,
)
}
)
@@ -604,7 +604,6 @@ class AttributeValueCreate(ModelMutation):
@classmethod
def perform_mutation(cls, _root, info, attribute_id, input):
attribute = cls.get_node_or_error(info, attribute_id, only_type=Attribute)
-
instance = models.AttributeValue(attribute=attribute)
cleaned_input = cls.clean_input(info, instance, input)
instance = cls.construct_instance(instance, cleaned_input)
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.py
index 14cd89fc0c..93523f04b3 100644
--- a/saleor/graphql/product/mutations/products.py
+++ b/saleor/graphql/product/mutations/products.py
@@ -573,7 +573,7 @@ class AttributeAssignmentMixin:
f"Could not resolve to a node: ids={global_ids}"
f" and slugs={list(slugs)}"
),
- code=ProductErrorCode.NOT_FOUND,
+ code=ProductErrorCode.NOT_FOUND.value,
)
nodes_pk_list = set()
@@ -586,14 +586,14 @@ class AttributeAssignmentMixin:
if pk not in nodes_pk_list:
raise ValidationError(
f"Could not resolve {global_id!r} to Attribute",
- code=ProductErrorCode.NOT_FOUND,
+ code=ProductErrorCode.NOT_FOUND.value,
)
for slug in slugs:
if slug not in nodes_slug_list:
raise ValidationError(
f"Could not resolve slug {slug!r} to Attribute",
- code=ProductErrorCode.NOT_FOUND,
+ code=ProductErrorCode.NOT_FOUND.value,
)
return nodes
@@ -605,12 +605,12 @@ class AttributeAssignmentMixin:
if graphene_type != "Attribute":
raise ValidationError(
f"Must receive an Attribute id, got {graphene_type}.",
- code=ProductErrorCode.INVALID,
+ code=ProductErrorCode.INVALID.value,
)
if not internal_id.isnumeric():
raise ValidationError(
f"An invalid ID value was passed: {global_id}",
- code=ProductErrorCode.INVALID,
+ code=ProductErrorCode.INVALID.value,
)
return int(internal_id)
@@ -647,7 +647,7 @@ class AttributeAssignmentMixin:
if qs.filter(missing_required_filter).exists():
raise ValidationError(
"All attributes flagged as having a value required must be supplied.",
- code=ProductErrorCode.REQUIRED,
+ code=ProductErrorCode.REQUIRED.value,
)
@classmethod
@@ -661,7 +661,7 @@ class AttributeAssignmentMixin:
"""
if len(cleaned_input) != qs.count():
raise ValidationError(
- "All attributes must take a value", code=ProductErrorCode.REQUIRED
+ "All attributes must take a value", code=ProductErrorCode.REQUIRED.value
)
for attribute, values in cleaned_input:
@@ -717,7 +717,7 @@ class AttributeAssignmentMixin:
else:
raise ValidationError(
"You must whether supply an ID or a slug",
- code=ProductErrorCode.REQUIRED,
+ code=ProductErrorCode.REQUIRED.value,
)
attributes = cls._resolve_attribute_nodes(
@@ -746,8 +746,10 @@ class AttributeAssignmentMixin:
:param cleaned_input: the cleaned user input (refer to clean_attributes)
"""
for attribute, values in cleaned_input:
- values = cls._pre_save_values(attribute, values)
- associate_attribute_values_to_instance(instance, attribute, *values)
+ attribute_values = cls._pre_save_values(attribute, values)
+ associate_attribute_values_to_instance(
+ instance, attribute, *attribute_values
+ )
class ProductCreate(ModelMutation):
@@ -1087,7 +1089,9 @@ class ProductVariantCreate(ModelMutation):
used_attribute_values.append(attribute_values)
@classmethod
- def clean_input(cls, info, instance: models.ProductVariant, data: dict):
+ def clean_input(
+ cls, info, instance: models.ProductVariant, data: dict, input_cls=None
+ ):
cleaned_input = super().clean_input(info, instance, data)
if "cost_price" in cleaned_input: