Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix attributes save performance (#14924) (#15361)
Iga Karbowiakb6f1b04ceeb3
diff --git a/saleor/attribute/tests/test_utils.py b/saleor/attribute/tests/test_utils.pyindex 06d758256f..a288bf23c7 100644--- a/saleor/attribute/tests/test_utils.py+++ b/saleor/attribute/tests/test_utils.py@@ -19,7 +19,10 @@ def test_associate_attribute_to_non_product_instance(color_attribute):value = color_attribute.values.first()with pytest.raises(AssertionError) as exc:- associate_attribute_values_to_instance(instance, attribute, value) # noqa+ associate_attribute_values_to_instance(+ instance,+ {attribute.id: [value]},+ ) # noqaassert exc.value.args == ("ProductType is unsupported",)@@ -32,7 +35,10 @@ def test_associate_attribute_to_product_instance_from_different_attribute(value = size_attribute.values.first()with pytest.raises(AssertionError) as exc:- associate_attribute_values_to_instance(instance, attribute, value)+ associate_attribute_values_to_instance(+ instance,+ {attribute.id: [value]},+ )assert exc.value.args == ("Some values are not from the provided attribute.",)@@ -45,7 +51,7 @@ def test_associate_attribute_to_product_instance_without_values(product):assert value_count == 1, "Product doesn't have attribute-values"# Clear the values- associate_attribute_values_to_instance(product, attribute)+ associate_attribute_values_to_instance(product, {attribute.id: []})# Ensure the values were cleared and no new assignment entry was createdassert get_product_attributes(product).count() == 1@@ -60,7 +66,7 @@ def test_disassociate_attributes_from_instance(product):assert value_count == 1, "Product doesn't have attribute-values"# This should clear the values- associate_attribute_values_to_instance(product, attribute)+ associate_attribute_values_to_instance(product, {attribute.id: []})# Check that the attribute still belongs to the product but doesn't have valuesattribute = get_product_attributes(product).first()@@ -85,7 +91,9 @@ def test_associate_attribute_to_product_instance_multiple_values(values = attribute.values.all()# Assign new values- associate_attribute_values_to_instance(product, attribute, values[1], values[0])+ associate_attribute_values_to_instance(+ product, {attribute.id: [values[1], values[0]]}+ )# Ensure the new assignment was created and ordered correctlyassert product.attributevalues.count() == 2@@ -104,7 +112,7 @@ def test_associate_attribute_to_page_instance_multiple_values(page):values = attribute.values.all()# Clear the values- associate_attribute_values_to_instance(page, attribute, values[1], values[0])+ associate_attribute_values_to_instance(page, {attribute.id: [values[1], values[0]]})# Ensure the new assignment was created and ordered correctlyassigned_values = (@@ -133,10 +141,11 @@ def test_associate_attribute_to_variant_instance_multiple_values()values = attribute.values.all()- new_assignment = associate_attribute_values_to_instance(- variant, attribute, values[0], values[1]+ associate_attribute_values_to_instance(+ variant, {attribute.id: [values[0], values[1]]})+ new_assignment = variant.attributes.last()# Ensure the new assignment was created and ordered correctlyassert new_assignment.values.count() == 2assert list(@@ -157,7 +166,7 @@ def test_associate_attribute_to_product_copies_data_over_to_new_field(# Assign new valuesassociate_attribute_values_to_instance(- product, color_attribute, values[0], values[1]+ product, {color_attribute.id: [values[0], values[1]]})# Ensure the new assignment was createddiff --git a/saleor/attribute/utils.py b/saleor/attribute/utils.pyindex 7b5012c809..17cd94aff9 100644--- a/saleor/attribute/utils.py+++ b/saleor/attribute/utils.py@@ -1,7 +1,7 @@-from collections.abc import Iterable+from collections import defaultdictfrom typing import Union-from django.db.models.expressions import Exists, OuterRef+from django.db.models import Exists, OuterReffrom ..page.models import Pagefrom ..product.models import Product, ProductVariant@@ -10,7 +10,8 @@ from .models import (AssignedProductAttributeValue,AssignedVariantAttribute,AssignedVariantAttributeValue,- Attribute,+ AttributePage,+ AttributeProduct,AttributeValue,AttributeVariant,)@@ -18,191 +19,223 @@ from .models import (T_INSTANCE = Union[Product, ProductVariant, Page]+instance_to_function_variables_mapping = {+ "Product": (+ AttributeProduct,+ AssignedProductAttributeValue,+ "product",+ ),+ "ProductVariant": (+ AttributeVariant,+ AssignedVariantAttributeValue,+ "variant",+ ),+ "Page": (AttributePage, AssignedPageAttributeValue, "page"),+}++def associate_attribute_values_to_instance(- instance: T_INSTANCE,- attribute: Attribute,- *values: AttributeValue,-) -> Union[None, AssignedVariantAttribute]:- """Assign given attribute values to a product or variant.-- Note: be aware this function invokes the ``set`` method on the instance's- attribute association. Meaning any values already assigned or concurrently+ instance: T_INSTANCE, attr_val_map: dict[int, list]+):+ """Assign given attribute values to a product, variant or page.++ Note: be aware any values already assigned or concurrentlyassigned will be overridden by this call."""- values_ids = {value.pk for value in values}# Ensure the values are actually form the given attribute- validate_attribute_owns_values(attribute, values_ids)+ validate_attribute_owns_values(attr_val_map)# Associate the attribute and the passed values- return _associate_attribute_to_instance(instance, attribute, *values)+ _associate_attribute_to_instance(instance, attr_val_map)-def validate_attribute_owns_values(attribute: Attribute, value_ids: set[int]) -> None:- """Check if given value IDs belong to the given Attribute.+def validate_attribute_owns_values(attr_val_map: dict[int, list]) -> None:+ values = defaultdict(set)+ for value in AttributeValue.objects.filter(+ attribute_id__in=attr_val_map.keys(),+ pk__in=[v.pk for values in attr_val_map.values() for v in values],+ ).iterator():+ values[value.attribute_id].add(value.id)- :raise: AssertionError- """- attribute_actual_value_ids = set(- AttributeValue.objects.filter(- pk__in=value_ids, attribute=attribute- ).values_list("pk", flat=True)- )- if attribute_actual_value_ids != value_ids:- raise AssertionError("Some values are not from the provided attribute.")+ for attribute_id, value_ids in attr_val_map.items():+ if values[attribute_id] != {v.pk for v in value_ids}:+ raise AssertionError("Some values are not from the provided attribute.")def _associate_attribute_to_instance(- instance: T_INSTANCE,- attribute: Attribute,- *values: AttributeValue,-) -> Union[None, AssignedVariantAttribute]:- """Associate a given attribute to an instance.-- For a given instance assign an attribute to it and set values based on *values.+ instance: T_INSTANCE, attr_val_map: dict[int, list]+):+ instance_type = instance.__class__.__name__+ variables = instance_to_function_variables_mapping.get(instance_type)- Note: this will clean any value that already exist there.+ if not variables:+ raise AssertionError(f"{instance_type} is unsupported")- This function is under rebuilding while we move away from intermediate models- for attribute relations+ (+ instance_attribute_model,+ value_model,+ instance_field_name,+ ) = variables- See:- https://github.com/saleor/saleor/issues/12881- """- if isinstance(instance, Page):- # Clear all assignments that don't match the values we'd like to assign- value_ids = [value.pk for value in values]- values_qs = AttributeValue.objects.filter(attribute_id=attribute.pk)- AssignedPageAttributeValue.objects.filter(- Exists(values_qs.filter(id=OuterRef("value_id"))),- page_id=instance.pk,- ).exclude(value_id__in=value_ids).delete()+ assignments = []+ if isinstance(instance, ProductVariant):+ prod_type_id = instance.product.product_type_id+ attribute_filter: dict[str, Union[int, list[int]]] = {+ "attribute_id__in": list(attr_val_map.keys()),+ "product_type_id": prod_type_id,+ }+ instance_attrs_ids = instance_attribute_model.objects.filter( # type: ignore+ **attribute_filter+ ).values_list("pk", flat=True)- # Create new assignments- # Spend on db query to check values that are in the db so that we can use bulk_create- # to set the new assignments- # This code will be able to use bulk_create option ignore_conflicts once- # unique_together is set for product + value on AssignedProductAttributeValue- existing_page_values = AssignedPageAttributeValue.objects.filter(- page=instance, value_id__in=value_ids- ).values_list("value_id", flat=True)- new_values = list(set(value_ids) - set(existing_page_values))-- AssignedPageAttributeValue.objects.bulk_create(- AssignedPageAttributeValue(page=instance, value_id=value_id)- for value_id in new_values+ assignments = _get_or_create_assignments(+ instance, instance_attrs_ids, AssignedVariantAttribute, instance_field_name)- sort_assigned_attribute_values(instance, attribute, values)- return None+ values_order_map = _overwrite_values(+ instance,+ assignments,+ attr_val_map,+ value_model,+ None if instance_field_name == "variant" else instance_field_name,+ )- if isinstance(instance, Product):- # Clear all assignments that don't match the values we'd like to assign- value_ids = [value.pk for value in values]+ if isinstance(instance, ProductVariant):+ _order_variant_assigned_attr_values(+ values_order_map, assignments, attr_val_map, AssignedVariantAttributeValue+ )+ else:+ _order_assigned_attr_values(+ values_order_map, attr_val_map, value_model, instance_field_name, instance+ )- values_qs = AttributeValue.objects.filter(attribute_id=attribute.pk)- AssignedProductAttributeValue.objects.filter(- Exists(values_qs.filter(id=OuterRef("value_id"))),- product_id=instance.pk,- ).exclude(value_id__in=value_ids).delete()- # Create new assignments- # Spend on db query to check values that are in the db so that we can use bulk_create- # to set the new assignments- # This code will be able to use bulk_create option ignore_conflicts once- # unique_together is set for product + value on AssignedProductAttributeValue- existing_product_values = AssignedProductAttributeValue.objects.filter(- product=instance, value_id__in=value_ids- ).values_list("value_id", flat=True)- new_values = list(set(value_ids) - set(existing_product_values))-- AssignedProductAttributeValue.objects.bulk_create(- AssignedProductAttributeValue(product=instance, value_id=value_id)- for value_id in new_values+def _get_or_create_assignments(+ instance, instance_attrs_ids, assignment_model, instance_field_name+):+ instance_field_kwarg = {instance_field_name: instance}+ assignments = list(+ assignment_model.objects.filter(+ assignment_id__in=instance_attrs_ids, **instance_field_kwarg)+ )- sort_assigned_attribute_values(instance, attribute, values)- return None+ assignments_to_create = []+ for id in instance_attrs_ids:+ if id not in [a.assignment_id for a in assignments]:+ assignments_to_create.append(id)++ if assignments_to_create:+ assignments += list(+ assignment_model.objects.bulk_create(+ [+ assignment_model(+ assignment_id=assignment_id, **instance_field_kwarg+ )+ for assignment_id in assignments_to_create+ ]+ )+ )+ return assignments- if isinstance(instance, ProductVariant):- assignment: AssignedVariantAttribute- attribute_variant = AttributeVariant.objects.get(- attribute_id=attribute.pk,- product_type_id=instance.product.product_type_id,+def _overwrite_values(+ instance, assignments, attr_val_map, value_assignment_model, instance_field_name+) -> dict[int, list]:+ instance_field_kwarg = (+ {instance_field_name: instance} if instance_field_name else {}+ )++ value_ids = [v.id for values in attr_val_map.values() for v in values]+ new_value_ids = value_ids+ assignment_attr_map = {a.assignment.attribute_id: a for a in assignments}+ if isinstance(instance, ProductVariant):+ value_assignment_model.objects.filter(+ assignment_id__in=[a.pk for a in assignments],+ ).exclude(value_id__in=value_ids).delete()+ else:+ values_qs = AttributeValue.objects.filter(+ attribute_id__in=list(attr_val_map.keys())+ )+ value_ids = [v.pk for values in attr_val_map.values() for v in values]+ assigned_values = value_assignment_model.objects.filter(+ Exists(values_qs.filter(id=OuterRef("value_id"))), **instance_field_kwarg)- assignment, _ = AssignedVariantAttribute.objects.get_or_create(- variant=instance, assignment=attribute_variant+ # Clear all assignments that don't match the values we'd like to assign+ assigned_values.exclude(value_id__in=value_ids).delete()++ new_value_ids = list(+ set(value_ids) - set(assigned_values.values_list("value_id", flat=True)))- assignment.values.set(values)- sort_assigned_attribute_values_using_assignment(instance, assignment, values)- return assignment- raise AssertionError(f"{instance.__class__.__name__} is unsupported")+ # Create new assignments+ # Spend on db query to check values that are in the db so that we can use bulk_create+ # to set the new assignments+ # This code will be able to use bulk_create option ignore_conflicts once+ # unique_together is set for product + value on AssignedProductAttributeValue+ values_order_map = defaultdict(list)+ assigned_attr_values_instances = []+ for attr_id, values in attr_val_map.items():+ assignment = assignment_attr_map.get(attr_id)++ for value in values:+ if value.id not in new_value_ids:+ values_order_map[attr_id].append(value.id)+ continue++ params = {"value": value, **instance_field_kwarg}+ if assignment:+ params["assignment_id"] = assignment.id+ assigned_attr_values_instances.append(value_assignment_model(**params))+ if assignment:+ values_order_map[assignment.id].append(value.id)+ else:+ values_order_map[attr_id].append(value.id)++ value_assignment_model.objects.bulk_create(+ assigned_attr_values_instances, ignore_conflicts=True+ )+ return values_order_map-def sort_assigned_attribute_values_using_assignment(- instance: ProductVariant,- assignment: AssignedVariantAttribute,- values: Iterable[AttributeValue],+def _order_assigned_attr_values(+ values_order_map, attr_val_map, assignment_model, instance_field_name, instance) -> None:- """Sort assigned attribute values based on values list order."""- instance_to_value_assignment_mapping = {- "ProductVariant": ("variantvalueassignment", AssignedVariantAttributeValue),+ instance_field_kwarg = (+ {instance_field_name: instance} if instance_field_name else {}+ )++ value_id_to_attribute_id = {+ v.id: attr_id for attr_id, values in attr_val_map.items() for v in values}- assignment_lookup, assignment_model = instance_to_value_assignment_mapping[- instance.__class__.__name__- ]- values_pks = [value.pk for value in values]+ attribute_ids = list(attr_val_map.keys())- values_assignment = list(- getattr(assignment, assignment_lookup).select_related("value")+ values_qs = AttributeValue.objects.filter(attribute_id__in=attribute_ids)+ assigned_values = list(+ assignment_model.objects.filter(+ Exists(values_qs.filter(id=OuterRef("value_id"))),+ **instance_field_kwarg,+ ).iterator())+ for value in assigned_values:+ attribute_id = value_id_to_attribute_id[value.value_id]+ value.sort_order = values_order_map[attribute_id].index(value.value_id)- values_assignment.sort(key=lambda e: values_pks.index(e.value.pk))- for index, value_assignment in enumerate(values_assignment):- value_assignment.sort_order = index+ assignment_model.objects.bulk_update(assigned_values, ["sort_order"])- assignment_model._default_manager.bulk_update(values_assignment, ["sort_order"])+ return-def sort_assigned_attribute_values(- instance: Union[Page, Product],- attribute: Attribute,- values: Iterable[AttributeValue],+def _order_variant_assigned_attr_values(+ values_order_map, assignments, attr_val_map, assignment_model) -> None:- values_pks = [value.pk for value in values]- values_qs = AttributeValue.objects.filter(attribute_id=attribute.pk)-- if isinstance(instance, Page):- assigned_page_values = list(- AssignedPageAttributeValue.objects.filter(- Exists(values_qs.filter(id=OuterRef("value_id"))),- page_id=instance.pk,- ).iterator()- )- assigned_page_values.sort(key=lambda e: values_pks.index(e.value_id))- for index, page_value_assignment in enumerate(assigned_page_values):- page_value_assignment.sort_order = index- AssignedPageAttributeValue.objects.bulk_update(- assigned_page_values,- ["sort_order"],- )- return-- if isinstance(instance, Product):- assigned_product_values = list(- AssignedProductAttributeValue.objects.filter(- Exists(values_qs.filter(id=OuterRef("value_id"))),- product=instance.pk,- ).iterator()- )- assigned_product_values.sort(key=lambda e: values_pks.index(e.value_id))- for index, product_value_assignment in enumerate(assigned_product_values):- product_value_assignment.sort_order = index- AssignedProductAttributeValue.objects.bulk_update(- assigned_product_values,- ["sort_order"],- )- return+ assigned_attrs_values = assignment_model.objects.filter(+ assignment_id__in=(a.pk for a in assignments),+ value_id__in=(v.pk for values in attr_val_map.values() for v in values),+ )+ for value in assigned_attrs_values:+ value.sort_order = values_order_map[value.assignment_id].index(value.value_id)++ assignment_model.objects.bulk_update(assigned_attrs_values, ["sort_order"])diff --git a/saleor/csv/tests/export/products_data/test_get_products_data.py b/saleor/csv/tests/export/products_data/test_get_products_data.pyindex 7eb6ce1573..03114c4f62 100644--- a/saleor/csv/tests/export/products_data/test_get_products_data.py+++ b/saleor/csv/tests/export/products_data/test_get_products_data.py@@ -296,41 +296,36 @@ def test_get_products_data_for_specified_warehouses_channels_and_attributes(# add boolean attributeassociate_attribute_values_to_instance(variant_with_many_stocks,- boolean_attribute,- boolean_attribute.values.first(),+ {boolean_attribute.pk: [boolean_attribute.values.first()]},)associate_attribute_values_to_instance(- product, boolean_attribute, boolean_attribute.values.first()+ product, {boolean_attribute.pk: [boolean_attribute.values.first()]})# add date attributeassociate_attribute_values_to_instance(- variant_with_many_stocks,- date_attribute,- date_attribute.values.first(),+ variant_with_many_stocks, {date_attribute.pk: [date_attribute.values.first()]})associate_attribute_values_to_instance(- product, date_attribute, date_attribute.values.first()+ product, {date_attribute.pk: [date_attribute.values.first()]})# add date time attributeassociate_attribute_values_to_instance(variant_with_many_stocks,- date_time_attribute,- date_time_attribute.values.first(),+ {date_time_attribute.pk: [date_time_attribute.values.first()]},)associate_attribute_values_to_instance(- product, date_time_attribute, date_time_attribute.values.first()+ product, {date_time_attribute.pk: [date_time_attribute.values.first()]})# add rich text attributeassociate_attribute_values_to_instance(variant_with_many_stocks,- rich_text_attribute,- rich_text_attribute.values.first(),+ {rich_text_attribute.pk: [rich_text_attribute.values.first()]},)associate_attribute_values_to_instance(- product, rich_text_attribute, rich_text_attribute.values.first()+ product, {rich_text_attribute.pk: [rich_text_attribute.values.first()]})# add page reference attribute@@ -348,11 +343,10 @@ def test_get_products_data_for_specified_warehouses_channels_and_attributes()associate_attribute_values_to_instance(variant_with_many_stocks,- product_type_page_reference_attribute,- variant_page_ref_value,+ {product_type_page_reference_attribute.pk: [variant_page_ref_value]},)associate_attribute_values_to_instance(- product, product_type_page_reference_attribute, product_page_ref_value+ product, {product_type_page_reference_attribute.pk: [product_page_ref_value]})# add product reference attribute@@ -373,11 +367,11 @@ def test_get_products_data_for_specified_warehouses_channels_and_attributes()associate_attribute_values_to_instance(variant_with_many_stocks,- product_type_product_reference_attribute,- variant_product_ref_value,+ {product_type_product_reference_attribute.pk: [variant_product_ref_value]},)associate_attribute_values_to_instance(- product, product_type_product_reference_attribute, product_product_ref_value+ product,+ {product_type_product_reference_attribute.pk: [product_product_ref_value]},)# add variant reference attribute@@ -395,11 +389,11 @@ def test_get_products_data_for_specified_warehouses_channels_and_attributes()associate_attribute_values_to_instance(variant_with_many_stocks,- product_type_variant_reference_attribute,- variant_variant_ref_value,+ {product_type_variant_reference_attribute.pk: [variant_variant_ref_value]},)associate_attribute_values_to_instance(- product, product_type_variant_reference_attribute, product_variant_ref_value+ product,+ {product_type_variant_reference_attribute.pk: [product_variant_ref_value]},)# add numeric attribute@@ -407,21 +401,28 @@ def test_get_products_data_for_specified_warehouses_channels_and_attributes(numeric_value_2 = numeric_attribute.values.last()associate_attribute_values_to_instance(- variant_with_many_stocks, numeric_attribute, numeric_value_1+ variant_with_many_stocks, {numeric_attribute.pk: [numeric_value_1]}+ )+ associate_attribute_values_to_instance(+ product, {numeric_attribute.pk: [numeric_value_2]})- associate_attribute_values_to_instance(product, numeric_attribute, numeric_value_2)# create assigned product without values- associate_attribute_values_to_instance(product, color_attribute)+ associate_attribute_values_to_instance(+ product, {color_attribute.pk: [color_attribute.values.first()]}+ )+ product.attributevalues.all().delete()# add swatch attributeswatch_value_1 = swatch_attribute.values.first()swatch_value_2 = swatch_attribute.values.last()associate_attribute_values_to_instance(- variant_with_many_stocks, swatch_attribute, swatch_value_1+ variant_with_many_stocks, {swatch_attribute.pk: [swatch_value_1]}+ )+ associate_attribute_values_to_instance(+ product, {swatch_attribute.pk: [swatch_value_2]})- associate_attribute_values_to_instance(product, swatch_attribute, swatch_value_2)products = Product.objects.all()export_fields = {"id", "variants__sku"}diff --git a/saleor/csv/tests/export/products_data/test_handle_relations_data.py b/saleor/csv/tests/export/products_data/test_handle_relations_data.pyindex 23971360e0..ab347ece6d 100644--- a/saleor/csv/tests/export/products_data/test_handle_relations_data.py+++ b/saleor/csv/tests/export/products_data/test_handle_relations_data.py@@ -95,7 +95,8 @@ def test_get_products_relations_data_attribute_ids(product_type_product_reference_attribute,)associate_attribute_values_to_instance(- product, file_attribute, file_attribute.values.first()+ product,+ {file_attribute.id: [file_attribute.values.first()]},)page_ref_value = AttributeValue.objects.create(attribute=product_type_page_reference_attribute,@@ -103,7 +104,8 @@ def test_get_products_relations_data_attribute_ids(name=page.title,)associate_attribute_values_to_instance(- product, product_type_page_reference_attribute, page_ref_value+ product,+ {product_type_page_reference_attribute.id: [page_ref_value]},)product_ref_value = AttributeValue.objects.create(attribute=product_type_product_reference_attribute,@@ -111,7 +113,8 @@ def test_get_products_relations_data_attribute_ids(name=product_list[1].name,)associate_attribute_values_to_instance(- product, product_type_product_reference_attribute, product_ref_value+ product,+ {product_type_product_reference_attribute.id: [product_ref_value]},)qs = Product.objects.all()@@ -169,7 +172,8 @@ def test_prepare_products_relations_data(file_attribute, product_type_page_reference_attribute)associate_attribute_values_to_instance(- product_with_image, file_attribute, file_attribute.values.first()+ product_with_image,+ {file_attribute.id: [file_attribute.values.first()]},)ref_value = AttributeValue.objects.create(attribute=product_type_page_reference_attribute,@@ -179,7 +183,8 @@ def test_prepare_products_relations_data(date_time=None,)associate_attribute_values_to_instance(- product_with_image, product_type_page_reference_attribute, ref_value+ product_with_image,+ {product_type_page_reference_attribute.id: [ref_value]},)collection_list[0].products.add(product_with_image)@@ -366,7 +371,8 @@ def test_get_variants_relations_data_attribute_ids()variant = product.variants.first()associate_attribute_values_to_instance(- variant, file_attribute, file_attribute.values.first()+ variant,+ {file_attribute.id: [file_attribute.values.first()]},)# add page reference attributepage_ref_value = AttributeValue.objects.create(@@ -375,7 +381,8 @@ def test_get_variants_relations_data_attribute_ids(name=page.title,)associate_attribute_values_to_instance(- variant, product_type_page_reference_attribute, page_ref_value+ variant,+ {product_type_page_reference_attribute.id: [page_ref_value]},)# add product reference attributeproduct_ref_value = AttributeValue.objects.create(@@ -384,7 +391,8 @@ def test_get_variants_relations_data_attribute_ids(name=product_list[1].name,)associate_attribute_values_to_instance(- variant, product_type_product_reference_attribute, product_ref_value+ variant,+ {product_type_product_reference_attribute.id: [product_ref_value]},)qs = Product.objects.all()@@ -503,7 +511,8 @@ def test_prepare_variants_relations_data()variant = product_1.variants.first()associate_attribute_values_to_instance(- variant, file_attribute, file_attribute.values.first()+ variant,+ {file_attribute.id: [file_attribute.values.first()]},)# add page reference attributepage_ref_value = AttributeValue.objects.create(@@ -513,7 +522,8 @@ def test_prepare_variants_relations_data(name=page.title,)associate_attribute_values_to_instance(- variant, product_type_page_reference_attribute, page_ref_value+ variant,+ {product_type_page_reference_attribute.id: [page_ref_value]},)# add prodcut reference attributeproduct_ref_value = AttributeValue.objects.create(@@ -523,7 +533,8 @@ def test_prepare_variants_relations_data(name=product.name,)associate_attribute_values_to_instance(- variant, product_type_product_reference_attribute, product_ref_value+ variant,+ {product_type_product_reference_attribute.id: [product_ref_value]},)qs = Product.objects.all()diff --git a/saleor/graphql/attribute/tests/benchmark/test_attribute.py b/saleor/graphql/attribute/tests/benchmark/test_attribute.pyindex 8c3637ca2a..42fdcc664a 100644--- a/saleor/graphql/attribute/tests/benchmark/test_attribute.py+++ b/saleor/graphql/attribute/tests/benchmark/test_attribute.py@@ -170,7 +170,7 @@ def test_attribute_value_translation(product.product_type.product_attributes.add(rich_text_attribute_with_many_values)associate_attribute_values_to_instance(- product, rich_text_attribute_with_many_values, *attribute_values+ product, {rich_text_attribute_with_many_values.pk: attribute_values})variables = {"slug": product.slug}diff --git a/saleor/graphql/attribute/tests/mutations/test_attribute_value_delete.py b/saleor/graphql/attribute/tests/mutations/test_attribute_value_delete.pyindex de05417ecf..9848ae8ea9 100644--- a/saleor/graphql/attribute/tests/mutations/test_attribute_value_delete.py+++ b/saleor/graphql/attribute/tests/mutations/test_attribute_value_delete.py@@ -182,7 +182,7 @@ def test_delete_attribute_value_product_search_document_updated(product_type = product.product_typeproduct_type.product_attributes.add(attribute)- associate_attribute_values_to_instance(product, attribute, value)+ associate_attribute_values_to_instance(product, {attribute.pk: [value]})query = ATTRIBUTE_VALUE_DELETE_MUTATIONnode_id = graphene.Node.to_global_id("AttributeValue", value.id)@@ -213,7 +213,7 @@ def test_delete_attribute_value_product_search_document_updated_variant_attributproduct_type = product.product_typeproduct_type.variant_attributes.add(attribute)- associate_attribute_values_to_instance(variant, attribute, value)+ associate_attribute_values_to_instance(variant, {attribute.pk: [value]})query = ATTRIBUTE_VALUE_DELETE_MUTATIONnode_id = graphene.Node.to_global_id("AttributeValue", value.id)diff --git a/saleor/graphql/attribute/tests/mutations/test_attribute_value_update.py b/saleor/graphql/attribute/tests/mutations/test_attribute_value_update.pyindex 61107b849c..feeeca598d 100644--- a/saleor/graphql/attribute/tests/mutations/test_attribute_value_update.py+++ b/saleor/graphql/attribute/tests/mutations/test_attribute_value_update.py@@ -266,7 +266,7 @@ def test_update_attribute_value_product_search_document_updated(product_type = product.product_typeproduct_type.product_attributes.add(attribute)- associate_attribute_values_to_instance(product, attribute, value)+ associate_attribute_values_to_instance(product, {attribute.pk: [value]})node_id = graphene.Node.to_global_id("AttributeValue", value.id)name = "Crimson name"@@ -303,7 +303,7 @@ def test_update_attribute_value_product_search_document_updated_variant_attributproduct_type = product.product_typeproduct_type.variant_attributes.add(attribute)- associate_attribute_values_to_instance(variant, attribute, value)+ associate_attribute_values_to_instance(variant, {attribute.pk: [value]})node_id = graphene.Node.to_global_id("AttributeValue", value.id)name = "Crimson name"diff --git a/saleor/graphql/attribute/tests/mutations/test_bulk_delete.py b/saleor/graphql/attribute/tests/mutations/test_bulk_delete.pyindex 6440e25168..9f5e494d0d 100644--- a/saleor/graphql/attribute/tests/mutations/test_bulk_delete.py+++ b/saleor/graphql/attribute/tests/mutations/test_bulk_delete.py@@ -117,12 +117,18 @@ def test_delete_attributes_products_search_document_updated(attr_3_name = "attr 3 value"attr_3_value = AttributeValue.objects.create(name=attr_3_name, attribute=attr_3)- associate_attribute_values_to_instance(product_1, attr_1, attr_1_value)associate_attribute_values_to_instance(- product_1, color_attribute, color_attribute_value+ product_1,+ {attr_1.id: [attr_1_value], color_attribute.id: [color_attribute_value]},+ )+ associate_attribute_values_to_instance(+ product_2,+ {attr_2.id: [attr_2_value]},+ )+ associate_attribute_values_to_instance(+ variant_1,+ {attr_3.id: [attr_3_value]},)- associate_attribute_values_to_instance(product_2, attr_2, attr_2_value)- associate_attribute_values_to_instance(variant_1, attr_3, attr_3_value)variables = {"ids": [@@ -231,9 +237,18 @@ def test_delete_attribute_values_search_document_updated(product_type.product_attributes.add(attribute)product_type.variant_attributes.add(attribute)- associate_attribute_values_to_instance(product_1, attribute, value_1, value_4)- associate_attribute_values_to_instance(product_2, attribute, value_2)- associate_attribute_values_to_instance(variant_1, attribute, value_3)+ associate_attribute_values_to_instance(+ product_1,+ {attribute.id: [value_1, value_4]},+ )+ associate_attribute_values_to_instance(+ product_2,+ {attribute.id: [value_2]},+ )+ associate_attribute_values_to_instance(+ variant_1,+ {attribute.id: [value_3]},+ )variables = {"ids": [diff --git a/saleor/graphql/attribute/tests/queries/test_attribute_filter.py b/saleor/graphql/attribute/tests/queries/test_attribute_filter.pyindex e0077193d8..658ac8bcd3 100644--- a/saleor/graphql/attribute/tests/queries/test_attribute_filter.py+++ b/saleor/graphql/attribute/tests/queries/test_attribute_filter.py@@ -187,7 +187,7 @@ def test_filter_attributes_in_category_invalid_category_id(last_product.channel_listings.all().update(visible_in_listings=False)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1], {weight_attribute.pk: [weight_attribute.values.first()]})variables = {@@ -229,7 +229,7 @@ def test_filter_attributes_in_category_object_with_given_id_does_not_exist(last_product.channel_listings.all().update(visible_in_listings=False)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1], {weight_attribute.pk: [weight_attribute.values.first()]})variables = {@@ -266,7 +266,7 @@ def test_filter_attributes_in_category_not_visible_in_listings_by_customer(last_product.channel_listings.all().update(visible_in_listings=False)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1], {weight_attribute.pk: [weight_attribute.values.first()]})attribute_count = Attribute.objects.count()@@ -316,7 +316,7 @@ def test_filter_attributes_in_category_not_visible_in_listings_by_staff_with_perlast_product.channel_listings.all().update(visible_in_listings=False)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1], {weight_attribute.pk: [weight_attribute.values.first()]})attribute_count = Attribute.objects.count()@@ -360,7 +360,7 @@ def test_filter_attributes_in_category_not_in_listings_by_staff_without_manage_plast_product.channel_listings.all().update(visible_in_listings=False)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1], {weight_attribute.pk: [weight_attribute.values.first()]})attribute_count = Attribute.objects.count()@@ -407,7 +407,7 @@ def test_filter_attributes_in_category_not_visible_in_listings_by_app_with_perm(last_product.channel_listings.all().update(visible_in_listings=False)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1], {weight_attribute.pk: [weight_attribute.values.first()]})attribute_count = Attribute.objects.count()@@ -451,7 +451,7 @@ def test_filter_attributes_in_category_not_in_listings_by_app_without_manage_prolast_product.channel_listings.all().update(visible_in_listings=False)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1], {weight_attribute.pk: [weight_attribute.values.first()]})attribute_count = Attribute.objects.count()@@ -492,7 +492,7 @@ def test_filter_attributes_in_category_not_published_by_customer(last_product.channel_listings.all().update(is_published=False)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1], {weight_attribute.pk: [weight_attribute.values.first()]})attribute_count = Attribute.objects.count()@@ -542,7 +542,7 @@ def test_filter_attributes_in_category_not_published_by_staff_with_perm(last_product.channel_listings.all().update(is_published=False)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1], {weight_attribute.pk: [weight_attribute.values.first()]})attribute_count = Attribute.objects.count()@@ -586,7 +586,7 @@ def test_filter_attributes_in_category_not_published_by_staff_without_manage_prolast_product.channel_listings.all().update(is_published=False)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1], {weight_attribute.pk: [weight_attribute.values.first()]})attribute_count = Attribute.objects.count()@@ -633,7 +633,7 @@ def test_filter_attributes_in_category_not_published_by_app_with_perm(last_product.channel_listings.all().update(is_published=False)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1], {weight_attribute.pk: [weight_attribute.values.first()]})attribute_count = Attribute.objects.count()@@ -677,7 +677,7 @@ def test_filter_attributes_in_category_not_published_by_app_without_manage_produlast_product.channel_listings.all().update(is_published=False)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1], {weight_attribute.pk: [weight_attribute.values.first()]})attribute_count = Attribute.objects.count()@@ -721,7 +721,7 @@ def test_filter_attributes_in_collection_invalid_category_id(collection.products.add(product)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1], {weight_attribute.pk: [weight_attribute.values.first()]})variables = {@@ -766,7 +766,7 @@ def test_filter_attributes_in_collection_object_with_given_id_does_not_exist(collection.products.add(product)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1], {weight_attribute.pk: [weight_attribute.values.first()]})variables = {@@ -806,7 +806,7 @@ def test_filter_attributes_in_collection_not_visible_in_listings_by_customer(collection.products.add(product)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1], {weight_attribute.pk: [weight_attribute.values.first()]})attribute_count = Attribute.objects.count()@@ -849,7 +849,7 @@ def test_filter_in_collection_not_published_by_customer(collection.products.add(product)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1], {weight_attribute.pk: [weight_attribute.values.first()]})attribute_count = Attribute.objects.count()@@ -902,7 +902,7 @@ def test_filter_in_collection_not_published_by_staff_with_perm(collection.products.add(product)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1], {weight_attribute.pk: [weight_attribute.values.first()]})attribute_count = Attribute.objects.count()@@ -949,7 +949,7 @@ def test_filter_in_collection_not_published_by_staff_without_manage_products(collection.products.add(product)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1], {weight_attribute.pk: [weight_attribute.values.first()]})attribute_count = Attribute.objects.count()@@ -999,7 +999,7 @@ def test_filter_in_collection_not_published_by_app_with_perm(collection.products.add(product)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1], {weight_attribute.pk: [weight_attribute.values.first()]})attribute_count = Attribute.objects.count()@@ -1046,7 +1046,7 @@ def test_filter_in_collection_not_published_by_app_without_manage_products(collection.products.add(product)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1], {weight_attribute.pk: [weight_attribute.values.first()]})attribute_count = Attribute.objects.count()diff --git a/saleor/graphql/attribute/tests/queries/test_attribute_where.py b/saleor/graphql/attribute/tests/queries/test_attribute_where.pyindex 58adf80724..05034fd368 100644--- a/saleor/graphql/attribute/tests/queries/test_attribute_where.py+++ b/saleor/graphql/attribute/tests/queries/test_attribute_where.py@@ -495,7 +495,8 @@ def test_attributes_filter_attributes_in_collection_not_visible_in_listings_by_ccollection.products.add(product)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1],+ {weight_attribute.pk: [weight_attribute.values.first()]},)attribute_count = Attribute.objects.count()@@ -538,7 +539,8 @@ def test_attributes_filter_in_collection_not_published_by_customer(collection.products.add(product)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1],+ {weight_attribute.pk: [weight_attribute.values.first()]},)attribute_count = Attribute.objects.count()@@ -591,7 +593,8 @@ def test_attributes_filter_in_collection_not_published_by_staff_with_perm(collection.products.add(product)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1],+ {weight_attribute.pk: [weight_attribute.values.first()]},)attribute_count = Attribute.objects.count()@@ -638,7 +641,8 @@ def test_attributes_filter_in_collection_not_published_by_staff_without_manage_pcollection.products.add(product)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1],+ {weight_attribute.pk: [weight_attribute.values.first()]},)attribute_count = Attribute.objects.count()@@ -688,7 +692,8 @@ def test_attributes_filter_in_collection_not_published_by_app_with_perm(collection.products.add(product)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1],+ {weight_attribute.pk: [weight_attribute.values.first()]},)attribute_count = Attribute.objects.count()@@ -735,7 +740,8 @@ def test_attributes_filter_in_collection_not_published_by_app_without_manage_procollection.products.add(product)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1],+ {weight_attribute.pk: [weight_attribute.values.first()]},)attribute_count = Attribute.objects.count()@@ -778,7 +784,8 @@ def test_attributes_filter_attributes_in_collection_invalid_collection_id(collection.products.add(product)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1],+ {weight_attribute.pk: [weight_attribute.values.first()]},)variables = {@@ -823,7 +830,8 @@ def test_attributes_filter_attributes_in_collection_object_with_given_id_does_nocollection.products.add(product)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1],+ {weight_attribute.pk: [weight_attribute.values.first()]},)variables = {@@ -870,7 +878,8 @@ def test_attributes_filter_in_collection_empty_value(collection.products.add(product)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1],+ {weight_attribute.pk: [weight_attribute.values.first()]},)variables = {@@ -908,7 +917,8 @@ def test_attributes_filter_in_category_not_visible_in_listings_by_customer(last_product.channel_listings.all().update(visible_in_listings=False)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1],+ {weight_attribute.pk: [weight_attribute.values.first()]},)attribute_count = Attribute.objects.count()@@ -958,7 +968,8 @@ def test_attributes_filter_in_category_not_visible_in_listings_by_staff_with_perlast_product.channel_listings.all().update(visible_in_listings=False)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1],+ {weight_attribute.pk: [weight_attribute.values.first()]},)attribute_count = Attribute.objects.count()@@ -1002,7 +1013,8 @@ def test_attributes_filter_in_category_not_in_listings_by_staff_without_manage_plast_product.channel_listings.all().update(visible_in_listings=False)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1],+ {weight_attribute.pk: [weight_attribute.values.first()]},)attribute_count = Attribute.objects.count()@@ -1049,7 +1061,8 @@ def test_attributes_filter_in_category_not_visible_in_listings_by_app_with_perm(last_product.channel_listings.all().update(visible_in_listings=False)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1],+ {weight_attribute.pk: [weight_attribute.values.first()]},)attribute_count = Attribute.objects.count()@@ -1093,7 +1106,8 @@ def test_attributes_filter_in_category_not_in_listings_by_app_without_manage_prolast_product.channel_listings.all().update(visible_in_listings=False)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1],+ {weight_attribute.pk: [weight_attribute.values.first()]},)attribute_count = Attribute.objects.count()@@ -1134,7 +1148,8 @@ def test_attributes_filter_in_category_not_published_by_customer(last_product.channel_listings.all().update(is_published=False)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1],+ {weight_attribute.pk: [weight_attribute.values.first()]},)attribute_count = Attribute.objects.count()@@ -1184,7 +1199,8 @@ def test_attributes_filter_in_category_not_published_by_staff_with_perm(last_product.channel_listings.all().update(is_published=False)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1],+ {weight_attribute.pk: [weight_attribute.values.first()]},)attribute_count = Attribute.objects.count()@@ -1228,7 +1244,8 @@ def test_attributes_filter_in_category_not_published_by_staff_without_manage_prolast_product.channel_listings.all().update(is_published=False)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1],+ {weight_attribute.pk: [weight_attribute.values.first()]},)attribute_count = Attribute.objects.count()@@ -1275,7 +1292,8 @@ def test_attributes_filter_in_category_not_published_by_app_with_perm(last_product.channel_listings.all().update(is_published=False)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1],+ {weight_attribute.pk: [weight_attribute.values.first()]},)attribute_count = Attribute.objects.count()@@ -1319,7 +1337,8 @@ def test_attributes_filter_in_category_not_published_by_app_without_manage_produlast_product.channel_listings.all().update(is_published=False)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1],+ {weight_attribute.pk: [weight_attribute.values.first()]},)attribute_count = Attribute.objects.count()@@ -1360,7 +1379,8 @@ def test_attributes_filter_in_category_invalid_category_id(last_product.channel_listings.all().update(visible_in_listings=False)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1],+ {weight_attribute.pk: [weight_attribute.values.first()]},)variables = {@@ -1402,7 +1422,8 @@ def test_attributes_filter_in_category_object_with_given_id_does_not_exist(last_product.channel_listings.all().update(visible_in_listings=False)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1],+ {weight_attribute.pk: [weight_attribute.values.first()]},)variables = {@@ -1445,7 +1466,8 @@ def test_attributes_filter_in_category_empty_value(last_product.channel_listings.all().update(visible_in_listings=False)associate_attribute_values_to_instance(- product_list[-1], weight_attribute, weight_attribute.values.first()+ product_list[-1],+ {weight_attribute.pk: [weight_attribute.values.first()]},)variables = {diff --git a/saleor/graphql/attribute/tests/queries/test_attributes_sort.py b/saleor/graphql/attribute/tests/queries/test_attributes_sort.pyindex 2f782152a0..1d9f3dc1c3 100644--- a/saleor/graphql/attribute/tests/queries/test_attributes_sort.py+++ b/saleor/graphql/attribute/tests/queries/test_attributes_sort.py@@ -91,7 +91,7 @@ def test_attributes_of_products_are_sorted_on_variant(# Assign attributes to the productassociate_attribute_values_to_instance(- variant, color_attribute, color_attribute.values.first()+ variant, {color_attribute.id: [color_attribute.values.first()]})# Sort the database attributes by their sort order and ID (when None)@@ -151,7 +151,7 @@ def test_attributes_of_products_are_sorted_on_product(# Assign attributes to the productAssignedProductAttributeValue.objects.filter(product_id=product.pk).delete()associate_attribute_values_to_instance(- product, color_attribute, color_attribute.values.first()+ product, {color_attribute.id: [color_attribute.values.first()]})# Sort the database attributes by their sort order and ID (when None)diff --git a/saleor/graphql/attribute/utils.py b/saleor/graphql/attribute/utils.pyindex 30883965af..47ffa896b2 100644--- a/saleor/graphql/attribute/utils.py+++ b/saleor/graphql/attribute/utils.py@@ -405,6 +405,7 @@ class AttributeAssignmentMixin:AttributeInputType.RICH_TEXT: cls._pre_save_rich_text_values,}clean_assignment = []+ attr_val_map = defaultdict(list)for attribute, attr_values in cleaned_input:is_handled_by_values_field = (@@ -422,11 +423,12 @@ class AttributeAssignmentMixin:pre_save_func = pre_save_methods_mapping[attribute.input_type]attribute_values = pre_save_func(instance, attribute, attr_values)- associate_attribute_values_to_instance(- instance, attribute, *attribute_values- )if not attribute_values:clean_assignment.append(attribute.pk)+ else:+ attr_val_map[attribute.pk].extend(attribute_values)++ associate_attribute_values_to_instance(instance, attr_val_map)# drop attribute assignment model when values are unassigned from instanceif clean_assignment:@@ -813,6 +815,9 @@ class PageAttributeAssignmentMixin(AttributeAssignmentMixin):AttributeInputType.RICH_TEXT: cls._pre_save_rich_text_values,}+ clean_assignment = []+ attr_val_map = defaultdict(list)+for attribute, attr_values in cleaned_input:is_handled_by_values_field = (attr_values.values@@ -829,9 +834,20 @@ class PageAttributeAssignmentMixin(AttributeAssignmentMixin):pre_save_func = pre_save_methods_mapping[attribute.input_type]attribute_values = pre_save_func(instance, attribute, attr_values)- associate_attribute_values_to_instance(- instance, attribute, *attribute_values+ if not attribute_values:+ clean_assignment.append(attribute.pk)+ else:+ attr_val_map[attribute.pk].extend(attribute_values)++ associate_attribute_values_to_instance(instance, attr_val_map)+ if clean_assignment:+ values = attribute_models.AttributeValue.objects.filter(+ attribute_id__in=clean_assignment)+ attribute_models.AssignedPageAttributeValue.objects.filter(+ Exists(values.filter(id=OuterRef("value_id"))),+ page_id=instance.pk,+ ).delete()class ProductAttributeAssignmentMixin(AttributeAssignmentMixin):@@ -883,6 +899,9 @@ class ProductAttributeAssignmentMixin(AttributeAssignmentMixin):AttributeInputType.RICH_TEXT: cls._pre_save_rich_text_values,}+ clean_assignment = []+ attr_val_map = defaultdict(list)+for attribute, attr_values in cleaned_input:is_handled_by_values_field = (attr_values.values@@ -899,9 +918,20 @@ class ProductAttributeAssignmentMixin(AttributeAssignmentMixin):pre_save_func = pre_save_methods_mapping[attribute.input_type]attribute_values = pre_save_func(instance, attribute, attr_values)- associate_attribute_values_to_instance(- instance, attribute, *attribute_values+ if not attribute_values:+ clean_assignment.append(attribute.pk)+ else:+ attr_val_map[attribute.pk].extend(attribute_values)++ associate_attribute_values_to_instance(instance, attr_val_map)+ if clean_assignment:+ values = attribute_models.AttributeValue.objects.filter(+ attribute_id__in=clean_assignment)+ attribute_models.AssignedProductAttributeValue.objects.filter(+ Exists(values.filter(id=OuterRef("value_id"))),+ product_id=instance.pk,+ ).delete()def prepare_attribute_values(attribute: attribute_models.Attribute, values: list[str]):diff --git a/saleor/graphql/page/tests/mutations/test_page_bulk_delete.py b/saleor/graphql/page/tests/mutations/test_page_bulk_delete.pyindex 2373aace91..96cca2a39e 100644--- a/saleor/graphql/page/tests/mutations/test_page_bulk_delete.py+++ b/saleor/graphql/page/tests/mutations/test_page_bulk_delete.py@@ -50,7 +50,7 @@ def test_page_bulk_delete_with_file_attribute(value = page_file_attribute.values.first()page_type.page_attributes.add(page_file_attribute)- associate_attribute_values_to_instance(page, page_file_attribute, value)+ associate_attribute_values_to_instance(page, {page_file_attribute.pk: [value]})variables = {"ids": [graphene.Node.to_global_id("Page", page.pk) for page in page_list]@@ -93,7 +93,7 @@ def test_page_delete_removes_reference_to_product()associate_attribute_values_to_instance(- product, product_type_page_reference_attribute, attr_value+ product, {product_type_page_reference_attribute.pk: [attr_value]})reference_id = graphene.Node.to_global_id("Page", page.pk)@@ -133,7 +133,7 @@ def test_page_delete_removes_reference_to_product_variant()associate_attribute_values_to_instance(- variant, product_type_page_reference_attribute, attr_value+ variant, {product_type_page_reference_attribute.pk: [attr_value]})reference_id = graphene.Node.to_global_id("Page", page.pk)@@ -175,7 +175,7 @@ def test_page_delete_removes_reference_to_page()associate_attribute_values_to_instance(- page, page_type_page_reference_attribute, attr_value+ page, {page_type_page_reference_attribute.pk: [attr_value]})reference_id = graphene.Node.to_global_id("Page", page_ref.pk)diff --git a/saleor/graphql/page/tests/mutations/test_page_delete.py b/saleor/graphql/page/tests/mutations/test_page_delete.pyindex 321f78c048..ba6034bfbe 100644--- a/saleor/graphql/page/tests/mutations/test_page_delete.py+++ b/saleor/graphql/page/tests/mutations/test_page_delete.py@@ -88,7 +88,9 @@ def test_page_delete_with_file_attribute(page_type = page.page_typepage_type.page_attributes.add(page_file_attribute)existing_value = page_file_attribute.values.first()- associate_attribute_values_to_instance(page, page_file_attribute, existing_value)+ associate_attribute_values_to_instance(+ page, {page_file_attribute.pk: [existing_value]}+ )variables = {"id": graphene.Node.to_global_id("Page", page.id)}@@ -127,7 +129,7 @@ def test_page_delete_removes_reference_to_product()associate_attribute_values_to_instance(- product, product_type_page_reference_attribute, attr_value+ product, {product_type_page_reference_attribute.pk: [attr_value]})reference_id = graphene.Node.to_global_id("Page", page.pk)@@ -167,7 +169,7 @@ def test_page_delete_removes_reference_to_product_variant()associate_attribute_values_to_instance(- variant, product_type_page_reference_attribute, attr_value+ variant, {product_type_page_reference_attribute.pk: [attr_value]})reference_id = graphene.Node.to_global_id("Page", page.pk)@@ -209,7 +211,7 @@ def test_page_delete_removes_reference_to_page()associate_attribute_values_to_instance(- page, page_type_page_reference_attribute, attr_value+ page, {page_type_page_reference_attribute.pk: [attr_value]})reference_id = graphene.Node.to_global_id("Page", page_ref.pk)diff --git a/saleor/graphql/page/tests/mutations/test_page_reorder_attribute_values.py b/saleor/graphql/page/tests/mutations/test_page_reorder_attribute_values.pyindex bc9ee500bb..fea621dbd8 100644--- a/saleor/graphql/page/tests/mutations/test_page_reorder_attribute_values.py+++ b/saleor/graphql/page/tests/mutations/test_page_reorder_attribute_values.py@@ -77,7 +77,7 @@ def test_sort_page_attribute_values(])associate_attribute_values_to_instance(- page, page_type_page_reference_attribute, *attr_values+ page, {page_type_page_reference_attribute.id: attr_values})variables = {@@ -147,7 +147,7 @@ def test_sort_page_attribute_values_invalid_attribute_id(])associate_attribute_values_to_instance(- page, page_type_page_reference_attribute, *attr_values+ page, {page_type_page_reference_attribute.id: attr_values})variables = {@@ -208,7 +208,7 @@ def test_sort_page_attribute_values_invalid_value_id(])associate_attribute_values_to_instance(- page, page_type_page_reference_attribute, *attr_values+ page, {page_type_page_reference_attribute.id: attr_values})invalid_value_id = graphene.Node.to_global_id(diff --git a/saleor/graphql/page/tests/mutations/test_page_type_delete.py b/saleor/graphql/page/tests/mutations/test_page_type_delete.pyindex ac9b58a32c..a345142784 100644--- a/saleor/graphql/page/tests/mutations/test_page_type_delete.py+++ b/saleor/graphql/page/tests/mutations/test_page_type_delete.py@@ -195,7 +195,7 @@ def test_page_type_delete_with_file_attributes(page_type.page_attributes.add(page_file_attribute)value = page_file_attribute.values.first()- associate_attribute_values_to_instance(page, page_file_attribute, value)+ associate_attribute_values_to_instance(page, {page_file_attribute.pk: [value]})page_type_id = graphene.Node.to_global_id("PageType", page_type.pk)variables = {"id": page_type_id}diff --git a/saleor/graphql/page/tests/mutations/test_page_types_bulk_delete.py b/saleor/graphql/page/tests/mutations/test_page_types_bulk_delete.pyindex a444aab227..b7b866dd50 100644--- a/saleor/graphql/page/tests/mutations/test_page_types_bulk_delete.py+++ b/saleor/graphql/page/tests/mutations/test_page_types_bulk_delete.py@@ -179,7 +179,7 @@ def test_page_type_bulk_delete_with_file_attribute(value = page_file_attribute.values.first()page_type.page_attributes.add(page_file_attribute)- associate_attribute_values_to_instance(page, page_file_attribute, value)+ associate_attribute_values_to_instance(page, {page_file_attribute.pk: [value]})pages_pks = list(Page.objects.filter(page_type__in=page_type_list).values_list("pk", flat=True)diff --git a/saleor/graphql/page/tests/mutations/test_page_update.py b/saleor/graphql/page/tests/mutations/test_page_update.pyindex f35725a6b6..71e088f2ab 100644--- a/saleor/graphql/page/tests/mutations/test_page_update.py+++ b/saleor/graphql/page/tests/mutations/test_page_update.py@@ -316,7 +316,9 @@ def test_update_page_with_file_attribute_new_value_is_not_created("Attribute", page_file_attribute.pk)existing_value = page_file_attribute.values.first()- associate_attribute_values_to_instance(page, page_file_attribute, existing_value)+ associate_attribute_values_to_instance(+ page, {page_file_attribute.pk: [existing_value]}+ )page_id = graphene.Node.to_global_id("Page", page.id)domain = site_settings.site.domain@@ -469,7 +471,7 @@ def test_update_page_with_page_reference_attribute_existing_value(reference_page=ref_page,)associate_attribute_values_to_instance(- page, page_type_page_reference_attribute, attr_value+ page, {page_type_page_reference_attribute.pk: [attr_value]})values_count = page_type_page_reference_attribute.values.count()@@ -751,7 +753,7 @@ def test_update_page_with_product_reference_attribute_existing_value(reference_product=product,)associate_attribute_values_to_instance(- page, page_type_product_reference_attribute, attr_value+ page, {page_type_product_reference_attribute.pk: [attr_value]})values_count = page_type_product_reference_attribute.values.count()@@ -871,7 +873,7 @@ def test_update_page_with_variant_reference_attribute_existing_value(reference_variant=variant,)associate_attribute_values_to_instance(- page, page_type_variant_reference_attribute, attr_value+ page, {page_type_variant_reference_attribute.pk: [attr_value]})values_count = page_type_variant_reference_attribute.values.count()@@ -1090,10 +1092,13 @@ def test_update_page_change_attribute_values_ordering(associate_attribute_values_to_instance(page,- page_type_product_reference_attribute,- attr_value_3,- attr_value_2,- attr_value_1,+ {+ page_type_product_reference_attribute.pk: [+ attr_value_3,+ attr_value_2,+ attr_value_1,+ ]+ },)attribute = get_page_attributes(page).first()diff --git a/saleor/graphql/page/tests/queries/test_page.py b/saleor/graphql/page/tests/queries/test_page.pyindex 265d829f10..bd6fef40d0 100644--- a/saleor/graphql/page/tests/queries/test_page.py+++ b/saleor/graphql/page/tests/queries/test_page.py@@ -294,7 +294,7 @@ def test_get_page_with_sorted_attribute_values(attr_values = [attr_value_2, attr_value_1, attr_value_3]associate_attribute_values_to_instance(- page, page_type_product_reference_attribute, *attr_values+ page, {page_type_product_reference_attribute.pk: attr_values})page_id = graphene.Node.to_global_id("Page", page.id)diff --git a/saleor/graphql/product/tests/benchmark/test_product.py b/saleor/graphql/product/tests/benchmark/test_product.pyindex 8ca262abab..6b61e6c3de 100644--- a/saleor/graphql/product/tests/benchmark/test_product.py+++ b/saleor/graphql/product/tests/benchmark/test_product.py@@ -469,6 +469,9 @@ def test_update_product(non_default_category,collection_list,product_with_variant_with_two_attributes,+ color_attribute,+ size_attribute,+ boolean_attribute,other_description_json,permission_manage_products,monkeypatch,@@ -533,6 +536,24 @@ def test_update_product(product_slug = "updated-product"product_charge_taxes = Trueproduct_tax_rate = "STANDARD"+ product.product_type.product_attributes.add(size_attribute)+ product.product_type.product_attributes.add(color_attribute)+ product.product_type.product_attributes.add(boolean_attribute)++ attributes = [+ {+ "id": graphene.Node.to_global_id("Attribute", color_attribute.pk),+ "values": ["newValue"],+ },+ {+ "id": graphene.Node.to_global_id("Attribute", size_attribute.pk),+ "values": ["newValue"],+ },+ {+ "id": graphene.Node.to_global_id("Attribute", boolean_attribute.pk),+ "values": ["False"],+ },+ ]# Mock tax interface with fake response from tax gatewaymonkeypatch.setattr(@@ -550,6 +571,7 @@ def test_update_product("description": other_description_json,"chargeTaxes": product_charge_taxes,"taxCode": product_tax_rate,+ "attributes": attributes,},}@@ -603,7 +625,7 @@ def test_filter_products_by_numeric_attributes(product = product_list[0]product.product_type.product_attributes.add(numeric_attribute)associate_attribute_values_to_instance(- product, numeric_attribute, *numeric_attribute.values.all()+ product, {numeric_attribute.id: list(numeric_attribute.values.all())})variables = {"channel": channel_USD.slug,@@ -630,7 +652,7 @@ def test_filter_products_by_boolean_attributes(product = product_list[0]product.product_type.product_attributes.add(boolean_attribute)associate_attribute_values_to_instance(- product, boolean_attribute, *boolean_attribute.values.all()+ product, {boolean_attribute.id: list(boolean_attribute.values.all())})variables = {"channel": channel_USD.slug,diff --git a/saleor/graphql/product/tests/mutations/test_product_delete.py b/saleor/graphql/product/tests/mutations/test_product_delete.pyindex bbdf3e093c..2229a69b45 100644--- a/saleor/graphql/product/tests/mutations/test_product_delete.py+++ b/saleor/graphql/product/tests/mutations/test_product_delete.py@@ -161,7 +161,9 @@ def test_delete_product_with_file_attribute(product_type = product.product_typeproduct_type.product_attributes.add(file_attribute)existing_value = file_attribute.values.first()- associate_attribute_values_to_instance(product, file_attribute, existing_value)+ associate_attribute_values_to_instance(+ product, {file_attribute.pk: [existing_value]}+ )node_id = graphene.Node.to_global_id("Product", product.id)variables = {"id": node_id}@@ -323,7 +325,7 @@ def test_product_delete_removes_reference_to_product(reference_product=product_ref,)associate_attribute_values_to_instance(- product, product_type_product_reference_attribute, attr_value+ product, {product_type_product_reference_attribute.pk: [attr_value]})reference_id = graphene.Node.to_global_id("Product", product_ref.pk)@@ -363,9 +365,7 @@ def test_product_delete_removes_reference_to_product_variant()associate_attribute_values_to_instance(- variant,- product_type_product_reference_attribute,- attr_value,+ variant, {product_type_product_reference_attribute.pk: [attr_value]})reference_id = graphene.Node.to_global_id("Product", product_list[0].pk)@@ -404,7 +404,7 @@ def test_product_delete_removes_reference_to_page(reference_product=product,)associate_attribute_values_to_instance(- page, page_type_product_reference_attribute, attr_value+ page, {page_type_product_reference_attribute.pk: [attr_value]})reference_id = graphene.Node.to_global_id("Product", product.pk)diff --git a/saleor/graphql/product/tests/mutations/test_product_type_delete.py b/saleor/graphql/product/tests/mutations/test_product_type_delete.pyindex c5db366f7e..9010ec12b8 100644--- a/saleor/graphql/product/tests/mutations/test_product_type_delete.py+++ b/saleor/graphql/product/tests/mutations/test_product_type_delete.py@@ -73,8 +73,7 @@ def test_product_type_delete_with_file_attributes(product_type.product_attributes.add(file_attribute)associate_attribute_values_to_instance(product_with_variant_with_file_attribute,- file_attribute,- file_attribute.values.last(),+ {file_attribute.pk: [file_attribute.values.last()]},)values = list(file_attribute.values.all())diff --git a/saleor/graphql/product/tests/mutations/test_product_update.py b/saleor/graphql/product/tests/mutations/test_product_update.pyindex 6d36af7692..cc0b5fa552 100644--- a/saleor/graphql/product/tests/mutations/test_product_update.py+++ b/saleor/graphql/product/tests/mutations/test_product_update.py@@ -590,8 +590,10 @@ def test_update_product_with_file_attribute_value_new_value_is_not_created(product_type.product_attributes.add(file_attribute)attribute_values = file_attribute.values.all()- existing_value = attribute_values[0]- associate_attribute_values_to_instance(product, file_attribute, existing_value)+ existing_value = file_attribute.values.first()+ associate_attribute_values_to_instance(+ product, {file_attribute.pk: [existing_value]}+ )values_count = len(attribute_values)domain = site_settings.site.domain@@ -716,7 +718,7 @@ def test_update_product_with_numeric_attribute_value_new_value_is_not_created(value = AttributeValue.objects.create(attribute=numeric_attribute, slug=slug_value, name="20.0")- associate_attribute_values_to_instance(product, numeric_attribute, value)+ associate_attribute_values_to_instance(product, {numeric_attribute.pk: [value]})value_count = AttributeValue.objects.count()@@ -819,7 +821,7 @@ def test_update_product_clean_boolean_attribute_value(product_type.product_attributes.add(boolean_attribute)associate_attribute_values_to_instance(- product, boolean_attribute, boolean_attribute.values.first()+ product, {boolean_attribute.pk: [boolean_attribute.values.first()]})product_attr = get_product_attributes(product).get(id=boolean_attribute.id)@@ -865,7 +867,7 @@ def test_update_product_clean_file_attribute_value(product_type.product_attributes.add(file_attribute)associate_attribute_values_to_instance(- product, file_attribute, file_attribute.values.first()+ product, {file_attribute.pk: [file_attribute.values.first()]})product_attr = get_product_attributes(product).get(pk=file_attribute.id)@@ -1301,7 +1303,7 @@ def test_update_product_with_page_reference_attribute_existing_value(reference_page=page,)associate_attribute_values_to_instance(- product, product_type_page_reference_attribute, attr_value+ product, {product_type_page_reference_attribute.pk: [attr_value]})values_count = product_type_page_reference_attribute.values.count()@@ -1588,7 +1590,7 @@ def test_update_product_with_product_reference_attribute_existing_value(reference_product=product_ref,)associate_attribute_values_to_instance(- product, product_type_product_reference_attribute, attr_value+ product, {product_type_product_reference_attribute.pk: [attr_value]})values_count = product_type_product_reference_attribute.values.count()@@ -1717,7 +1719,8 @@ def test_update_product_change_values_ordering()associate_attribute_values_to_instance(- product, product_type_page_reference_attribute, attr_value_2, attr_value_1+ product,+ {product_type_page_reference_attribute.pk: [attr_value_2, attr_value_1]},)attribute = get_product_attributes(product).first()@@ -2215,7 +2218,7 @@ def test_update_product_with_numeric_attribute_by_numeric_field_null_value(value = AttributeValue.objects.create(attribute=numeric_attribute, slug=slug_value, name="20.0")- associate_attribute_values_to_instance(product, numeric_attribute, value)+ associate_attribute_values_to_instance(product, {numeric_attribute.pk: [value]})variables = {"productId": product_id,@@ -2252,7 +2255,7 @@ def test_update_product_with_numeric_attribute_by_numeric_field_new_value_not_crvalue = AttributeValue.objects.create(attribute=numeric_attribute, slug=slug_value, name="20.0")- associate_attribute_values_to_instance(product, numeric_attribute, value)+ associate_attribute_values_to_instance(product, {numeric_attribute.pk: [value]})value_count = AttributeValue.objects.count()@@ -2570,7 +2573,7 @@ def test_update_product_with_multiselect_attribute_existing_values(attr_value_id_2 = graphene.Node.to_global_id("AttributeValue", attr_value_2.pk)attr_value_name_2 = attr_value_2.name- associate_attribute_values_to_instance(product, attribute, attr_value_1)+ associate_attribute_values_to_instance(product, {attribute.pk: [attr_value_1]})attribute = get_product_attributes(product).first()assert len(get_product_attribute_values(product, attribute)) == 1diff --git a/saleor/graphql/product/tests/mutations/test_product_variant_update.py b/saleor/graphql/product/tests/mutations/test_product_variant_update.pyindex 208c7da6c7..16f274009f 100644--- a/saleor/graphql/product/tests/mutations/test_product_variant_update.py+++ b/saleor/graphql/product/tests/mutations/test_product_variant_update.py@@ -878,7 +878,8 @@ def test_update_variant_with_boolean_attribute(}associate_attribute_values_to_instance(- variant, boolean_attribute, boolean_attribute.values.first()+ variant,+ {boolean_attribute.id: [boolean_attribute.values.first()]},)response = staff_api_client.post_graphql(@@ -1113,7 +1114,7 @@ def test_update_variant_with_rich_text_attribute(rich_text_attribute_value.save()values_count = rich_text_attribute.values.count()associate_attribute_values_to_instance(- variant, rich_text_attribute, rich_text_attribute.values.first()+ variant, {rich_text_attribute.id: [rich_text_attribute_value]})response = staff_api_client.post_graphql(@@ -1161,7 +1162,7 @@ def test_update_variant_with_plain_text_attribute(plain_text_attribute_value.save()values_count = plain_text_attribute.values.count()associate_attribute_values_to_instance(- variant, plain_text_attribute, plain_text_attribute.values.first()+ variant, {plain_text_attribute.id: [plain_text_attribute_value]})# when@@ -1216,7 +1217,7 @@ def test_update_variant_with_plain_text_attribute_value_required(values_count = plain_text_attribute.values.count()associate_attribute_values_to_instance(- variant, plain_text_attribute, plain_text_attribute.values.first()+ variant, {plain_text_attribute.id: [plain_text_attribute_value]})# when@@ -1259,7 +1260,7 @@ def test_update_variant_with_required_plain_text_attribute_no_value(plain_text_attribute_value.save()associate_attribute_values_to_instance(- variant, plain_text_attribute, plain_text_attribute.values.first()+ variant, {plain_text_attribute.id: [plain_text_attribute_value]})plain_text_attribute.value_required = True@@ -1439,7 +1440,9 @@ def test_update_variant_with_numeric_attribute(attribute_value.slug = f"{variant.id}_{numeric_attribute.id}"attribute_value.save()values_count = numeric_attribute.values.count()- associate_attribute_values_to_instance(variant, numeric_attribute, attribute_value)+ associate_attribute_values_to_instance(+ variant, {numeric_attribute.id: [attribute_value]}+ )response = staff_api_client.post_graphql(query, variables, permissions=[permission_manage_products]@@ -1557,10 +1560,11 @@ def test_update_product_variant_with_duplicated_attribute(variant2.sku = str(uuid4())[:12]variant2.save()associate_attribute_values_to_instance(- variant2, color_attribute, color_attribute.values.last()- )- associate_attribute_values_to_instance(- variant2, size_attribute, size_attribute.values.last()+ variant2,+ {+ color_attribute.id: [color_attribute.values.last()],+ size_attribute.id: [size_attribute.values.last()],+ },)assert variant.attributes.first().values.first().slug == "red"@@ -1659,7 +1663,9 @@ def test_update_product_variant_with_duplicated_file_attribute(variant2.sku = str(uuid4())[:12]variant2.save()file_attr_value = file_attribute.values.last()- associate_attribute_values_to_instance(variant2, file_attribute, file_attr_value)+ associate_attribute_values_to_instance(+ variant2, {file_attribute.id: [file_attr_value]}+ )sku = str(uuid4())[:12]assert not variant.sku == sku@@ -1951,10 +1957,13 @@ def test_update_product_variant_change_attribute_values_ordering(associate_attribute_values_to_instance(variant,- product_type_product_reference_attribute,- attr_value_3,- attr_value_2,- attr_value_1,+ {+ product_type_product_reference_attribute.id: [+ attr_value_3,+ attr_value_2,+ attr_value_1,+ ]+ },)assert list(diff --git a/saleor/graphql/product/tests/queries/test_product_query.py b/saleor/graphql/product/tests/queries/test_product_query.pyindex e17a022c0f..01d7f9b676 100644--- a/saleor/graphql/product/tests/queries/test_product_query.py+++ b/saleor/graphql/product/tests/queries/test_product_query.py@@ -1563,7 +1563,8 @@ def test_get_product_with_sorted_attribute_values()associate_attribute_values_to_instance(- product, product_type_page_reference_attribute, attr_value_2, attr_value_1+ product,+ {product_type_page_reference_attribute.pk: [attr_value_2, attr_value_1]},)product_id = graphene.Node.to_global_id("Product", product.id)diff --git a/saleor/graphql/product/tests/queries/test_products_query_with_filter.py b/saleor/graphql/product/tests/queries/test_products_query_with_filter.pyindex 5dfc9ab076..927861c3bc 100644--- a/saleor/graphql/product/tests/queries/test_products_query_with_filter.py+++ b/saleor/graphql/product/tests/queries/test_products_query_with_filter.py@@ -70,7 +70,10 @@ def test_products_query_with_filter_attributes(second_product.product_type = product_typesecond_product.slug = "second-product"second_product.save()- associate_attribute_values_to_instance(second_product, attribute, attr_value)+ associate_attribute_values_to_instance(+ second_product,+ {attribute.id: [attr_value]},+ )variables = {"filter": {@@ -116,7 +119,8 @@ def test_products_query_with_filter_numeric_attributes():product.product_type.product_attributes.add(numeric_attribute)associate_attribute_values_to_instance(- product, numeric_attribute, *numeric_attribute.values.all()+ product,+ {numeric_attribute.id: list(numeric_attribute.values.all())},)product_type = ProductType.objects.create(@@ -139,7 +143,8 @@ def test_products_query_with_filter_numeric_attributes()associate_attribute_values_to_instance(- second_product, numeric_attribute, attr_value+ second_product,+ {numeric_attribute.id: [attr_value]},)third_product = Product.objects.create(@@ -152,7 +157,10 @@ def test_products_query_with_filter_numeric_attributes(attribute=numeric_attribute, name="5", slug="5_X")- associate_attribute_values_to_instance(third_product, numeric_attribute, attr_value)+ associate_attribute_values_to_instance(+ third_product,+ {numeric_attribute.id: [attr_value]},+ )second_product.refresh_from_db()third_product.refresh_from_db()@@ -207,7 +215,8 @@ def test_products_query_with_filter_boolean_attributes(product.product_type.product_attributes.add(boolean_attribute)associate_attribute_values_to_instance(- product, boolean_attribute, boolean_attribute.values.get(boolean=filter_value)+ product,+ {boolean_attribute.id: [boolean_attribute.values.get(boolean=filter_value)]},)product_type = ProductType.objects.create(@@ -226,7 +235,8 @@ def test_products_query_with_filter_boolean_attributes(category=category,)associate_attribute_values_to_instance(- second_product, boolean_attribute, boolean_attribute.values.get(boolean=False)+ second_product,+ {boolean_attribute.id: [boolean_attribute.values.get(boolean=False)]},)second_product.refresh_from_db()@@ -267,7 +277,8 @@ def test_products_query_with_filter_by_attributes_values_and_range(attr_value_1 = get_product_attribute_values(product, product_attr).first()product.product_type.product_attributes.add(numeric_attribute)associate_attribute_values_to_instance(- product, numeric_attribute, *numeric_attribute.values.all()+ product,+ {numeric_attribute.id: list(numeric_attribute.values.all())},)product_type = ProductType.objects.create(@@ -290,7 +301,8 @@ def test_products_query_with_filter_by_attributes_values_and_range()associate_attribute_values_to_instance(- second_product, numeric_attribute, attr_value_2+ second_product,+ {numeric_attribute.id: [attr_value_2]},)second_product.refresh_from_db()@@ -326,7 +338,8 @@ def test_products_query_with_filter_swatch_attributes():product.product_type.product_attributes.add(swatch_attribute)associate_attribute_values_to_instance(- product, swatch_attribute, *swatch_attribute.values.all()+ product,+ {swatch_attribute.id: list(swatch_attribute.values.all())},)product_type = ProductType.objects.create(@@ -347,7 +360,10 @@ def test_products_query_with_filter_swatch_attributes(attribute=swatch_attribute, name="Dark", slug="dark")- associate_attribute_values_to_instance(second_product, swatch_attribute, attr_value)+ associate_attribute_values_to_instance(+ second_product,+ {swatch_attribute.id: [attr_value]},+ )second_product.refresh_from_db()@@ -396,13 +412,16 @@ def test_products_query_with_filter_date_range_date_attributes()associate_attribute_values_to_instance(- product_list[0], date_attribute, attr_value_1+ product_list[0],+ {date_attribute.id: [attr_value_1]},)associate_attribute_values_to_instance(- product_list[1], date_attribute, attr_value_2+ product_list[1],+ {date_attribute.id: [attr_value_2]},)associate_attribute_values_to_instance(- product_list[2], date_attribute, attr_value_3+ product_list[2],+ {date_attribute.id: [attr_value_3]},)variables = {@@ -457,13 +476,16 @@ def test_products_query_with_filter_date_range_date_variant_attributes()associate_attribute_values_to_instance(- product_list[0].variants.first(), date_attribute, attr_value_1+ product_list[0].variants.first(),+ {date_attribute.id: [attr_value_1]},)associate_attribute_values_to_instance(- product_list[1].variants.first(), date_attribute, attr_value_2+ product_list[1].variants.first(),+ {date_attribute.id: [attr_value_2]},)associate_attribute_values_to_instance(- product_list[2].variants.first(), date_attribute, attr_value_3+ product_list[2].variants.first(),+ {date_attribute.id: [attr_value_3]},)variables = {@@ -521,13 +543,16 @@ def test_products_query_with_filter_date_range_date_time_attributes()associate_attribute_values_to_instance(- product_list[0], date_time_attribute, attr_value_1+ product_list[0],+ {date_time_attribute.id: [attr_value_1]},)associate_attribute_values_to_instance(- product_list[1], date_time_attribute, attr_value_2+ product_list[1],+ {date_time_attribute.id: [attr_value_2]},)associate_attribute_values_to_instance(- product_list[2], date_time_attribute, attr_value_3+ product_list[2],+ {date_time_attribute.id: [attr_value_3]},)variables = {@@ -585,13 +610,16 @@ def test_products_query_with_filter_date_range_date_time_variant_attributes()associate_attribute_values_to_instance(- product_list[0].variants.first(), date_time_attribute, attr_value_1+ product_list[0].variants.first(),+ {date_time_attribute.id: [attr_value_1]},)associate_attribute_values_to_instance(- product_list[1].variants.first(), date_time_attribute, attr_value_2+ product_list[1].variants.first(),+ {date_time_attribute.id: [attr_value_2]},)associate_attribute_values_to_instance(- product_list[2].variants.first(), date_time_attribute, attr_value_3+ product_list[2].variants.first(),+ {date_time_attribute.id: [attr_value_3]},)variables = {@@ -653,13 +681,16 @@ def test_products_query_with_filter_date_time_range_date_time_attributes()associate_attribute_values_to_instance(- product_list[0], date_time_attribute, attr_value_1+ product_list[0],+ {date_time_attribute.id: [attr_value_1]},)associate_attribute_values_to_instance(- product_list[1].variants.first(), date_time_attribute, attr_value_2+ product_list[1].variants.first(),+ {date_time_attribute.id: [attr_value_2]},)associate_attribute_values_to_instance(- product_list[2].variants.first(), date_time_attribute, attr_value_3+ product_list[2].variants.first(),+ {date_time_attribute.id: [attr_value_3]},)variables = {@@ -1029,7 +1060,8 @@ def test_products_query_with_filter_search_by_dropdown_attribute_value(dropdown_attr_value.save(update_fields=["name"])associate_attribute_values_to_instance(- product_with_dropdown_attr, color_attribute, dropdown_attr_value+ product_with_dropdown_attr,+ {color_attribute.id: [dropdown_attr_value]},)product_with_dropdown_attr.refresh_from_db()@@ -1090,9 +1122,7 @@ def test_products_query_with_filter_search_by_multiselect_attribute_value(associate_attribute_values_to_instance(product_with_multiselect_attr,- multiselect_attribute,- multiselect_attr_val_1,- multiselect_attr_val_2,+ {multiselect_attribute.id: [multiselect_attr_val_1, multiselect_attr_val_2]},)product_with_multiselect_attr.refresh_from_db()@@ -1140,7 +1170,8 @@ def test_products_query_with_filter_search_by_rich_text_attribute(rich_text_value.save(update_fields=["rich_text"])associate_attribute_values_to_instance(- product_with_rich_text_attr, rich_text_attribute, rich_text_value+ product_with_rich_text_attr,+ {rich_text_attribute.id: [rich_text_value]},)product_with_rich_text_attr.refresh_from_db()@@ -1188,7 +1219,8 @@ def test_products_query_with_filter_search_by_plain_text_attribute(plain_text_value.save(update_fields=["plain_text"])associate_attribute_values_to_instance(- product_with_plain_text_attr, plain_text_attribute, plain_text_value+ product_with_plain_text_attr,+ {plain_text_attribute.id: [plain_text_value]},)product_with_plain_text_attr.refresh_from_db()@@ -1239,7 +1271,8 @@ def test_products_query_with_filter_search_by_numeric_attribute_value(numeric_attr_value.save(update_fields=["name"])associate_attribute_values_to_instance(- product_with_numeric_attr, numeric_attribute, numeric_attr_value+ product_with_numeric_attr,+ {numeric_attribute.id: [numeric_attr_value]},)product_with_numeric_attr.refresh_from_db()@@ -1286,7 +1319,8 @@ def test_products_query_with_filter_search_by_numeric_attribute_value_without_unnumeric_attr_value.save(update_fields=["name"])associate_attribute_values_to_instance(- product_with_numeric_attr, numeric_attribute, numeric_attr_value+ product_with_numeric_attr,+ {numeric_attribute.id: [numeric_attr_value]},)product_with_numeric_attr.refresh_from_db()@@ -1334,7 +1368,8 @@ def test_products_query_with_filter_search_by_date_attribute_value(date_attr_value.save(update_fields=["date_time"])associate_attribute_values_to_instance(- product_with_date_attr, date_attribute, date_attr_value+ product_with_date_attr,+ {date_attribute.id: [date_attr_value]},)product_with_date_attr.refresh_from_db()@@ -1382,7 +1417,8 @@ def test_products_query_with_filter_search_by_date_time_attribute_value(date_time_attr_value.save(update_fields=["date_time"])associate_attribute_values_to_instance(- product_with_date_time_attr, date_time_attribute, date_time_attr_value+ product_with_date_time_attr,+ {date_time_attribute.id: [date_time_attr_value]},)product_with_date_time_attr.refresh_from_db()diff --git a/saleor/graphql/product/tests/queries/test_products_query_with_where.py b/saleor/graphql/product/tests/queries/test_products_query_with_where.pyindex a1d197fb5b..861bfda71f 100644--- a/saleor/graphql/product/tests/queries/test_products_query_with_where.py+++ b/saleor/graphql/product/tests/queries/test_products_query_with_where.py@@ -671,7 +671,10 @@ def test_products_filter_by_attributes(product = product_list[0]product.product_type = product_typeproduct.save()- associate_attribute_values_to_instance(product, attribute, attr_value)+ associate_attribute_values_to_instance(+ product,+ {attribute.id: [attr_value]},+ )variables = {"channel": channel_USD.slug,@@ -714,7 +717,10 @@ def test_products_filter_by_attributes_empty_list(product = product_list[0]product.product_type = product_typeproduct.save()- associate_attribute_values_to_instance(product, attribute, attr_value)+ associate_attribute_values_to_instance(+ product,+ {attribute.id: [attr_value]},+ )variables = {"channel": channel_USD.slug,@@ -758,7 +764,8 @@ def test_products_filter_by_numeric_attributes(# givenproduct_list[0].product_type.product_attributes.add(numeric_attribute)associate_attribute_values_to_instance(- product_list[0], numeric_attribute, *numeric_attribute.values.all()+ product_list[0],+ {numeric_attribute.id: list(numeric_attribute.values.all())},)product_type = ProductType.objects.create(@@ -775,7 +782,8 @@ def test_products_filter_by_numeric_attributes(attribute=numeric_attribute, name="5", slug="5")associate_attribute_values_to_instance(- product_list[1], numeric_attribute, attr_value+ product_list[1],+ {numeric_attribute.id: [attr_value]},)attr_value = AttributeValue.objects.create(@@ -783,7 +791,8 @@ def test_products_filter_by_numeric_attributes()product_list[2].product_type = product_typeassociate_attribute_values_to_instance(- product_list[2], numeric_attribute, attr_value+ product_list[2],+ {numeric_attribute.id: [attr_value]},)variables = {@@ -819,8 +828,7 @@ def test_products_filter_by_boolean_attributes(product_list[0].product_type.product_attributes.add(boolean_attribute)associate_attribute_values_to_instance(product_list[0],- boolean_attribute,- boolean_attribute.values.get(boolean=filter_value),+ {boolean_attribute.id: [boolean_attribute.values.get(boolean=filter_value)]},)product_type = ProductType.objects.create(@@ -834,7 +842,8 @@ def test_products_filter_by_boolean_attributes(product_list[1].product_type = product_typeassociate_attribute_values_to_instance(- product_list[1], boolean_attribute, boolean_attribute.values.get(boolean=False)+ product_list[1],+ {boolean_attribute.id: [boolean_attribute.values.get(boolean=False)]},)variables = {@@ -868,7 +877,8 @@ def test_products_filter_by_attributes_values_and_range(attr_value_1 = get_product_attribute_values(product, product_attr).first()product_list[0].product_type.product_attributes.add(numeric_attribute)associate_attribute_values_to_instance(- product_list[0], numeric_attribute, *numeric_attribute.values.all()+ product_list[0],+ {numeric_attribute.id: list(numeric_attribute.values.all())},)product_type = ProductType.objects.create(@@ -885,7 +895,8 @@ def test_products_filter_by_attributes_values_and_range(attribute=numeric_attribute, name="1.2", slug="1_2")associate_attribute_values_to_instance(- product_list[1], numeric_attribute, attr_value_2+ product_list[1],+ {numeric_attribute.id: [attr_value_2]},)variables = {"channel": channel_USD.slug,@@ -919,7 +930,8 @@ def test_products_filter_by_swatch_attributes(# givenproduct_list[0].product_type.product_attributes.add(swatch_attribute)associate_attribute_values_to_instance(- product_list[0], swatch_attribute, *swatch_attribute.values.all()+ product_list[0],+ {swatch_attribute.id: list(swatch_attribute.values.all())},)product_type = ProductType.objects.create(@@ -935,7 +947,8 @@ def test_products_filter_by_swatch_attributes(attribute=swatch_attribute, name="Dark", slug="dark")associate_attribute_values_to_instance(- product_list[1], swatch_attribute, attr_value+ product_list[1],+ {swatch_attribute.id: [attr_value]},)variables = {@@ -979,13 +992,16 @@ def test_products_filter_by_date_range_date_attributes()associate_attribute_values_to_instance(- product_list[0], date_attribute, attr_value_1+ product_list[0],+ {date_attribute.id: [attr_value_1]},)associate_attribute_values_to_instance(- product_list[1], date_attribute, attr_value_2+ product_list[1],+ {date_attribute.id: [attr_value_2]},)associate_attribute_values_to_instance(- product_list[2], date_attribute, attr_value_3+ product_list[2],+ {date_attribute.id: [attr_value_3]},)variables = {@@ -1037,13 +1053,16 @@ def test_products_filter_by_date_range_date_variant_attributes()associate_attribute_values_to_instance(- product_list[0].variants.first(), date_attribute, attr_value_1+ product_list[0].variants.first(),+ {date_attribute.id: [attr_value_1]},)associate_attribute_values_to_instance(- product_list[1].variants.first(), date_attribute, attr_value_2+ product_list[1].variants.first(),+ {date_attribute.id: [attr_value_2]},)associate_attribute_values_to_instance(- product_list[2].variants.first(), date_attribute, attr_value_3+ product_list[2].variants.first(),+ {date_attribute.id: [attr_value_3]},)variables = {@@ -1098,13 +1117,16 @@ def test_products_filter_by_date_range_date_time_attributes()associate_attribute_values_to_instance(- product_list[0], date_time_attribute, attr_value_1+ product_list[0],+ {date_time_attribute.id: [attr_value_1]},)associate_attribute_values_to_instance(- product_list[1], date_time_attribute, attr_value_2+ product_list[1],+ {date_time_attribute.id: [attr_value_2]},)associate_attribute_values_to_instance(- product_list[2], date_time_attribute, attr_value_3+ product_list[2],+ {date_time_attribute.id: [attr_value_3]},)variables = {@@ -1159,13 +1181,16 @@ def test_products_filter_by_date_range_date_time_variant_attributes()associate_attribute_values_to_instance(- product_list[0].variants.first(), date_time_attribute, attr_value_1+ product_list[0].variants.first(),+ {date_time_attribute.id: [attr_value_1]},)associate_attribute_values_to_instance(- product_list[1].variants.first(), date_time_attribute, attr_value_2+ product_list[1].variants.first(),+ {date_time_attribute.id: [attr_value_2]},)associate_attribute_values_to_instance(- product_list[2].variants.first(), date_time_attribute, attr_value_3+ product_list[2].variants.first(),+ {date_time_attribute.id: [attr_value_3]},)variables = {@@ -1224,13 +1249,16 @@ def test_products_filter_by_date_time_range_date_time_attributes()associate_attribute_values_to_instance(- product_list[0], date_time_attribute, attr_value_1+ product_list[0],+ {date_time_attribute.id: [attr_value_1]},)associate_attribute_values_to_instance(- product_list[1].variants.first(), date_time_attribute, attr_value_2+ product_list[1].variants.first(),+ {date_time_attribute.id: [attr_value_2]},)associate_attribute_values_to_instance(- product_list[2].variants.first(), date_time_attribute, attr_value_3+ product_list[2].variants.first(),+ {date_time_attribute.id: [attr_value_3]},)variables = {diff --git a/saleor/graphql/product/tests/queries/test_variant_query.py b/saleor/graphql/product/tests/queries/test_variant_query.pyindex b7021ed2d4..5a7d29b827 100644--- a/saleor/graphql/product/tests/queries/test_variant_query.py+++ b/saleor/graphql/product/tests/queries/test_variant_query.py@@ -534,9 +534,12 @@ def test_get_variant_by_id_with_variant_selection_filter()_associate_attribute_to_instance(- variant, file_attribute_with_file_input_type_without_values+ variant,+ {+ file_attribute_with_file_input_type_without_values.pk: [],+ size_attribute.pk: [],+ },)- _associate_attribute_to_instance(variant, size_attribute)# whenresponse = staff_api_client.post_graphql(@@ -592,7 +595,7 @@ def test_get_variant_with_sorted_attribute_values(attr_values = [attr_value_2, attr_value_1, attr_value_3]associate_attribute_values_to_instance(- variant, product_type_product_reference_attribute, *attr_values+ variant, {product_type_product_reference_attribute.pk: attr_values})variant_id = graphene.Node.to_global_id("ProductVariant", variant.id)diff --git a/saleor/graphql/product/tests/test_attributes.py b/saleor/graphql/product/tests/test_attributes.pyindex 02bf42a382..c1fad82e32 100644--- a/saleor/graphql/product/tests/test_attributes.py+++ b/saleor/graphql/product/tests/test_attributes.py@@ -1031,7 +1031,10 @@ def test_unassign_attributes_from_product_type(product_attr_value = AttributeValue.objects.create(attribute=attribute, name="Test value", slug="test-value")- associate_attribute_values_to_instance(product, attribute, product_attr_value)+ associate_attribute_values_to_instance(+ product,+ {attribute.pk: [product_attr_value]},+ )remaining_attribute_global_id = graphene.Node.to_global_id("Attribute", product_attributes[1].pk@@ -1365,7 +1368,7 @@ def test_sort_product_attribute_values(])associate_attribute_values_to_instance(- product, product_type_page_reference_attribute, *attr_values+ product, {product_type_page_reference_attribute.pk: attr_values})variables = {@@ -1432,7 +1435,7 @@ def test_sort_product_attribute_values_invalid_attribute_id(])associate_attribute_values_to_instance(- product, product_type_page_reference_attribute, *attr_values+ product, {product_type_page_reference_attribute.pk: attr_values})variables = {@@ -1495,7 +1498,7 @@ def test_sort_product_attribute_values_invalid_value_id(])associate_attribute_values_to_instance(- product, product_type_page_reference_attribute, *attr_values+ product, {product_type_page_reference_attribute.pk: attr_values})invalid_value_id = graphene.Node.to_global_id(@@ -1600,7 +1603,7 @@ def test_sort_product_variant_attribute_values(])associate_attribute_values_to_instance(- variant, product_type_page_reference_attribute, *attr_values+ variant, {product_type_page_reference_attribute.pk: attr_values})variables = {@@ -1670,7 +1673,7 @@ def test_sort_product_variant_attribute_values_invalid_attribute_id(])associate_attribute_values_to_instance(- variant, product_type_page_reference_attribute, *attr_values+ variant, {product_type_page_reference_attribute.pk: attr_values})variables = {@@ -1734,7 +1737,7 @@ def test_sort_product_variant_attribute_values_invalid_value_id(])associate_attribute_values_to_instance(- variant, product_type_page_reference_attribute, *attr_values+ variant, {product_type_page_reference_attribute.pk: attr_values})invalid_value_id = graphene.Node.to_global_id(diff --git a/saleor/graphql/product/tests/test_bulk_delete.py b/saleor/graphql/product/tests/test_bulk_delete.pyindex f34b541aef..3a8caf15d9 100644--- a/saleor/graphql/product/tests/test_bulk_delete.py+++ b/saleor/graphql/product/tests/test_bulk_delete.py@@ -729,7 +729,9 @@ def test_delete_products_with_file_attributes(product_type = product.product_typeproduct_type.product_attributes.add(file_attribute)existing_value = values[i]- associate_attribute_values_to_instance(product, file_attribute, existing_value)+ associate_attribute_values_to_instance(+ product, {file_attribute.pk: [existing_value]}+ )variables = {"ids": [@@ -901,7 +903,9 @@ def test_delete_product_types_with_file_attributes(product.product_type = product_typeproduct.save()existing_value = values[i]- associate_attribute_values_to_instance(product, file_attribute, existing_value)+ associate_attribute_values_to_instance(+ product, {file_attribute.pk: [existing_value]}+ )variables = {"ids": [@@ -1324,7 +1328,7 @@ def test_product_delete_removes_reference_to_product(reference_product=product_ref,)associate_attribute_values_to_instance(- product, product_type_product_reference_attribute, attr_value+ product, {product_type_product_reference_attribute.id: [attr_value]})reference_id = graphene.Node.to_global_id("Product", product_ref.pk)@@ -1364,9 +1368,7 @@ def test_product_delete_removes_variant_reference_to_product()associate_attribute_values_to_instance(- variant,- product_type_product_reference_attribute,- attr_value,+ variant, {product_type_product_reference_attribute.id: [attr_value]})reference_id = graphene.Node.to_global_id("Product", product_list[0].pk)@@ -1407,7 +1409,7 @@ def test_product_delete_removes_reference_to_variant(reference_variant=variant_ref,)associate_attribute_values_to_instance(- product, product_type_variant_reference_attribute, attr_value+ product, {product_type_variant_reference_attribute.id: [attr_value]})product_id = graphene.Node.to_global_id("Product", product.pk)@@ -1450,7 +1452,7 @@ def test_product_delete_removes_reference_to_page(reference_product=product,)associate_attribute_values_to_instance(- page, page_type_product_reference_attribute, attr_value+ page, {page_type_product_reference_attribute.id: [attr_value]})reference_id = graphene.Node.to_global_id("Product", product.pk)@@ -1502,7 +1504,9 @@ def test_delete_product_variants_with_file_attribute(product_type = variant.product.product_typeproduct_type.variant_attributes.add(file_attribute)existing_value = values[i]- associate_attribute_values_to_instance(variant, file_attribute, existing_value)+ associate_attribute_values_to_instance(+ variant, {file_attribute.id: [existing_value]}+ )variables = {"ids": [diff --git a/saleor/graphql/product/tests/test_product_pagination.py b/saleor/graphql/product/tests/test_product_pagination.pyindex 1cbbfed907..bc4d475df9 100644--- a/saleor/graphql/product/tests/test_product_pagination.py+++ b/saleor/graphql/product/tests/test_product_pagination.py@@ -377,10 +377,10 @@ def products_for_pagination(product_attrib_values = color_attribute.values.all()associate_attribute_values_to_instance(- products[1], color_attribute, product_attrib_values[0]+ products[1], {color_attribute.id: [product_attrib_values[0]]})associate_attribute_values_to_instance(- products[3], color_attribute, product_attrib_values[1]+ products[3], {color_attribute.id: [product_attrib_values[1]]})variants = ProductVariant.objects.bulk_create(diff --git a/saleor/graphql/product/tests/test_product_sorting_attributes.py b/saleor/graphql/product/tests/test_product_sorting_attributes.pyindex 5c0308bab0..1962bdf551 100644--- a/saleor/graphql/product/tests/test_product_sorting_attributes.py+++ b/saleor/graphql/product/tests/test_product_sorting_attributes.py@@ -208,17 +208,24 @@ def products_structures(category, channel_USD):currency=channel_USD.currency_code,)dummy_attr_value = attr_value(dummy_attr, DUMMIES[0])- associate_attribute_values_to_instance(dummy, dummy_attr, *dummy_attr_value)+ associate_attribute_values_to_instance(+ dummy,+ {dummy_attr.pk: dummy_attr_value},+ )for products in (apples, oranges):for product, attr_values in zip(products, COLORS):attr_values = attr_value(colors_attr, *attr_values)- associate_attribute_values_to_instance(product, colors_attr, *attr_values)+ associate_attribute_values_to_instance(+ product,+ {colors_attr.pk: attr_values},+ )for product, attr_values in zip(products, TRADEMARKS):attr_values = attr_value(trademark_attr, attr_values)associate_attribute_values_to_instance(- product, trademark_attr, *attr_values+ product,+ {trademark_attr.pk: attr_values},)return colors_attr, trademark_attr, dummy_attr@@ -576,7 +583,10 @@ def test_sort_product_not_having_attribute_data(api_client, category, count_querproduct_having_attr_value = product_models.Product.objects.create(name="Z", slug="z", product_type=product_type, **product_create_kwargs)- associate_attribute_values_to_instance(product_having_attr_value, attribute, value)+ associate_attribute_values_to_instance(+ product_having_attr_value,+ {attribute.pk: [value]},+ )# Create a product having the same product type but no attribute dataproduct_models.Product.objects.create(diff --git a/saleor/graphql/translations/tests/test_translations.py b/saleor/graphql/translations/tests/test_translations.pyindex 5d752a2606..617ecbe9b9 100644--- a/saleor/graphql/translations/tests/test_translations.py+++ b/saleor/graphql/translations/tests/test_translations.py@@ -2217,7 +2217,8 @@ def test_plain_text_attribute_value_create_translation(attribute_value = plain_text_attribute.values.first()associate_attribute_values_to_instance(- variant, plain_text_attribute, attribute_value+ variant,+ {plain_text_attribute.pk: [attribute_value]},)attribute_value_id = graphene.Node.to_global_id("AttributeValue", attribute_value.id@@ -2504,7 +2505,8 @@ def test_plain_text_attribute_value_update_translation_only_plain_text(attribute_value = plain_text_attribute.values.first()associate_attribute_values_to_instance(- variant, plain_text_attribute, attribute_value+ variant,+ {plain_text_attribute.pk: [attribute_value]},)text = "Jakiś bazowy opis"@@ -2543,7 +2545,8 @@ def test_plain_text_attribute_value_update_translation_only_plain_text_long_textattribute_value = plain_text_attribute.values.first()associate_attribute_values_to_instance(- variant, plain_text_attribute, attribute_value+ variant,+ {plain_text_attribute.pk: [attribute_value]},)text = "Jakiś bazowy opis"@@ -2584,7 +2587,8 @@ def test_plain_text_attribute_value_update_translation_name_set_manually(attribute_value = plain_text_attribute.values.first()associate_attribute_values_to_instance(- variant, plain_text_attribute, attribute_value+ variant,+ {plain_text_attribute.pk: [attribute_value]},)text = "Jakiś bazowy opis"@@ -2624,7 +2628,8 @@ def test_plain_text_attribute_value_update_translation_empty_name(attribute_value = plain_text_attribute.values.first()associate_attribute_values_to_instance(- variant, plain_text_attribute, attribute_value+ variant,+ {plain_text_attribute.pk: [attribute_value]},)text = "Jakiś bazowy opis"@@ -2663,7 +2668,8 @@ def test_plain_text_attribute_value_update_translation_name_null(attribute_value = plain_text_attribute.values.first()associate_attribute_values_to_instance(- variant, plain_text_attribute, attribute_value+ variant,+ {plain_text_attribute.pk: [attribute_value]},)text = "Jakiś bazowy opis"@@ -3853,7 +3859,7 @@ def test_product_attribute_value_plain_text_translation(product_attr_value = plain_text_attribute.values.first()associate_attribute_values_to_instance(- product, plain_text_attribute, product_attr_value+ product, {plain_text_attribute.id: [product_attr_value]})text = "Test plain text translation"@@ -3894,7 +3900,7 @@ def test_nested_product_attribute_translation(product_attr_value = plain_text_attribute.values.first()associate_attribute_values_to_instance(- product, plain_text_attribute, product_attr_value+ product, {plain_text_attribute.id: [product_attr_value]})text = "Test attribute translation"@@ -4002,7 +4008,7 @@ def test_product_variant_attribute_value_plain_text_translation(attribute_value = plain_text_attribute.values.first()associate_attribute_values_to_instance(- variant, plain_text_attribute, attribute_value+ variant, {plain_text_attribute.id: [attribute_value]})text = "Test plain text translation"@@ -4043,7 +4049,7 @@ def test_nested_product_variant_attribute_translation(attribute_value = plain_text_attribute.values.first()associate_attribute_values_to_instance(- variant, plain_text_attribute, attribute_value+ variant, {plain_text_attribute.id: [attribute_value]})text = "Test attribute translation"@@ -4146,7 +4152,7 @@ def test_page_attribute_value_plain_text_translation(attribute_value = plain_text_attribute_page_type.values.first()associate_attribute_values_to_instance(- page, plain_text_attribute_page_type, attribute_value+ page, {plain_text_attribute_page_type.id: [attribute_value]})text = "Test plain text translation"@@ -4189,7 +4195,7 @@ def test_nested_page_attribute_translation(attribute_value = plain_text_attribute_page_type.values.first()associate_attribute_values_to_instance(- page, plain_text_attribute_page_type, attribute_value+ page, {plain_text_attribute_page_type.id: [attribute_value]})text = "Test attribute translation"diff --git a/saleor/product/tests/test_generate_and_set_variant_name.py b/saleor/product/tests/test_generate_and_set_variant_name.pyindex 074ab9d423..f24b702110 100644--- a/saleor/product/tests/test_generate_and_set_variant_name.py+++ b/saleor/product/tests/test_generate_and_set_variant_name.py@@ -69,8 +69,13 @@ def test_generate_and_set_variant_name_different_attributes(size = size_attribute.values.get(slug="big")# Associate the colors and size to variant attributes- associate_attribute_values_to_instance(variant, color_attribute, *tuple(colors))- associate_attribute_values_to_instance(variant, size_attribute, size)+ associate_attribute_values_to_instance(+ variant,+ {+ color_attribute.id: colors,+ size_attribute.id: [size],+ },+ )# Generate the variant name from the attributesgenerate_and_set_variant_name(variant, variant.sku)@@ -112,8 +117,13 @@ def test_generate_and_set_variant_name_only_variant_selection_attributes(size.save(update_fields=["sort_order"])# Associate the colors and size to variant attributes- associate_attribute_values_to_instance(variant, color_attribute, *tuple(colors))- associate_attribute_values_to_instance(variant, size_attribute, size)+ associate_attribute_values_to_instance(+ variant,+ {+ color_attribute.id: colors,+ size_attribute.id: [size],+ },+ )# Generate the variant name from the attributesgenerate_and_set_variant_name(variant, variant.sku)@@ -154,8 +164,13 @@ def test_generate_and_set_variant_name_only_not_variant_selection_attributes()# Associate the colors and size to variant attributes- associate_attribute_values_to_instance(variant, color_attribute, *values[:2])- associate_attribute_values_to_instance(variant, file_attribute, values[-1])+ associate_attribute_values_to_instance(+ variant,+ {+ color_attribute.id: values[:2],+ file_attribute.id: [values[-1]],+ },+ )# Generate the variant name from the attributesgenerate_and_set_variant_name(variant, variant.sku)diff --git a/saleor/product/tests/test_product.py b/saleor/product/tests/test_product.pyindex d91547e587..d3ef61b06e 100644--- a/saleor/product/tests/test_product.py+++ b/saleor/product/tests/test_product.py@@ -82,8 +82,14 @@ def test_filtering_by_attribute(color_2 = color_attribute.values.last()# Associate color to a product and a variant- associate_attribute_values_to_instance(product_a, color_attribute, color)- associate_attribute_values_to_instance(variant_b, color_attribute, color)+ associate_attribute_values_to_instance(+ product_a,+ {color_attribute.pk: [color]},+ )+ associate_attribute_values_to_instance(+ variant_b,+ {color_attribute.pk: [color]},+ )product_qs = models.Product.objects.all().values_list("pk", flat=True)@@ -92,7 +98,10 @@ def test_filtering_by_attribute(assert product_a.pk in list(filtered)assert product_b.pk in list(filtered)- associate_attribute_values_to_instance(product_a, color_attribute, color_2)+ associate_attribute_values_to_instance(+ product_a,+ {color_attribute.pk: [color_2]},+ )filters = {color_attribute.pk: [color.pk]}filtered = filter_products_by_attributes_values(product_qs, filters)@@ -114,7 +123,10 @@ def test_filtering_by_attribute(# Associate additional attribute to a productsize = size_attribute.values.first()product_type_a.product_attributes.add(size_attribute)- associate_attribute_values_to_instance(product_a, size_attribute, size)+ associate_attribute_values_to_instance(+ product_a,+ {size_attribute.pk: [size]},+ )# Filter by multiple attributesfilters = {color_attribute.pk: [color_2.pk], size_attribute.pk: [size.pk]}@@ -126,10 +138,16 @@ def test_filtering_by_attribute(product_type_b.product_attributes.add(date_attribute)date = date_attribute.values.first()- associate_attribute_values_to_instance(product_a, date_attribute, date)+ associate_attribute_values_to_instance(+ product_a,+ {date_attribute.pk: [date]},+ )date_2 = date_attribute.values.last()- associate_attribute_values_to_instance(product_b, date_attribute, date_2)+ associate_attribute_values_to_instance(+ product_b,+ {date_attribute.pk: [date_2]},+ )filters = {date_attribute.pk: [date.pk]}filtered = filter_products_by_attributes_values(product_qs, filters)diff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.pyindex aa5d0b1c80..5232d6d62b 100644--- a/saleor/tests/fixtures.py+++ b/saleor/tests/fixtures.py@@ -2461,7 +2461,7 @@ def categories_tree(db, product_type, channel_USD): # pylint: disable=W0613visible_in_listings=True,)- associate_attribute_values_to_instance(product, product_attr, attr_value)+ associate_attribute_values_to_instance(product, {product_attr.pk: [attr_value]})return parent@@ -2673,7 +2673,9 @@ def product(product_type, category, warehouse, channel_USD, default_tax_class):available_for_purchase_at=datetime.datetime(1999, 1, 1, tzinfo=pytz.UTC),)- associate_attribute_values_to_instance(product, product_attr, product_attr_value)+ associate_attribute_values_to_instance(+ product, {product_attr.pk: [product_attr_value]}+ )variant_attr = product_type.variant_attributes.first()variant_attr_value = variant_attr.values.first()@@ -2689,7 +2691,9 @@ def product(product_type, category, warehouse, channel_USD, default_tax_class):)Stock.objects.create(warehouse=warehouse, product_variant=variant, quantity=10)- associate_attribute_values_to_instance(variant, variant_attr, variant_attr_value)+ associate_attribute_values_to_instance(+ variant, {variant_attr.pk: [variant_attr_value]}+ )return product@@ -2859,7 +2863,9 @@ def product_with_rich_text_attribute(available_for_purchase_at=datetime.datetime(1999, 1, 1, tzinfo=pytz.UTC),)- associate_attribute_values_to_instance(product, product_attr, product_attr_value)+ associate_attribute_values_to_instance(+ product, {product_attr.pk: [product_attr_value]}+ )variant_attr = product_type_with_rich_text_attribute.variant_attributes.first()variant_attr_value = variant_attr.values.first()@@ -2875,7 +2881,9 @@ def product_with_rich_text_attribute()Stock.objects.create(warehouse=warehouse, product_variant=variant, quantity=10)- associate_attribute_values_to_instance(variant, variant_attr, variant_attr_value)+ associate_attribute_values_to_instance(+ variant, {variant_attr.pk: [variant_attr_value]}+ )return [product, variant]@@ -3029,10 +3037,10 @@ def product_with_variant_with_two_attributes()associate_attribute_values_to_instance(- variant, color_attribute, color_attribute.values.first()+ variant, {color_attribute.pk: [color_attribute.values.first()]})associate_attribute_values_to_instance(- variant, size_attribute, size_attribute.values.first()+ variant, {size_attribute.pk: [size_attribute.values.first()]})return product@@ -3092,10 +3100,10 @@ def product_with_variant_with_external_media()associate_attribute_values_to_instance(- variant, color_attribute, color_attribute.values.first()+ variant, {color_attribute.pk: [color_attribute.values.first()]})associate_attribute_values_to_instance(- variant, size_attribute, size_attribute.values.first()+ variant, {size_attribute.pk: [size_attribute.values.first()]})return product@@ -3143,7 +3151,7 @@ def product_with_variant_with_file_attribute()associate_attribute_values_to_instance(- variant, file_attribute, file_attribute.values.first()+ variant, {file_attribute.pk: [file_attribute.values.first()]})return product@@ -3168,7 +3176,9 @@ def product_with_multiple_values_attributes(product, product_type) -> Product:product_type.product_attributes.clear()product_type.product_attributes.add(attribute)- associate_attribute_values_to_instance(product, attribute, attr_val_1, attr_val_2)+ associate_attribute_values_to_instance(+ product, {attribute.pk: [attr_val_1, attr_val_2]}+ )return product@@ -3646,7 +3656,7 @@ def product_list(Stock.objects.bulk_create(stocks)for product in products:- associate_attribute_values_to_instance(product, product_attr, attr_value)+ associate_attribute_values_to_instance(product, {product_attr.pk: [attr_value]})product.search_vector = FlatConcatSearchVector(*prepare_product_search_vector_value(product))@@ -3929,7 +3939,9 @@ def unavailable_product_with_variant()Stock.objects.create(product_variant=variant, warehouse=warehouse, quantity=10)- associate_attribute_values_to_instance(variant, variant_attr, variant_attr_value)+ associate_attribute_values_to_instance(+ variant, {variant_attr.pk: [variant_attr_value]}+ )return product@@ -6222,7 +6234,9 @@ def page(db, page_type, size_page_attribute):# associate attribute valuepage_attr_value = size_page_attribute.values.get(slug="10")- associate_attribute_values_to_instance(page, size_page_attribute, page_attr_value)+ associate_attribute_values_to_instance(+ page, {size_page_attribute.pk: [page_attr_value]}+ )return page@@ -6241,10 +6255,10 @@ def page_with_rich_text_attribute(page = Page.objects.create(**data)# associate attribute value- page_attr_value = rich_text_attribute_page_type.values.first()- associate_attribute_values_to_instance(- page, rich_text_attribute_page_type, page_attr_value- )+ page_attr = page_type_with_rich_text_attribute.page_attributes.first()+ page_attr_value = page_attr.values.first()++ associate_attribute_values_to_instance(page, {page_attr.pk: [page_attr_value]})return page@@ -6381,7 +6395,7 @@ def translated_page_unique_attribute_value(page, rich_text_attribute_page_type):page_type.page_attributes.add(rich_text_attribute_page_type)attribute_value = rich_text_attribute_page_type.values.first()associate_attribute_values_to_instance(- page, rich_text_attribute_page_type, attribute_value+ page, {rich_text_attribute_page_type.id: [attribute_value]})return AttributeValueTranslation.objects.create(language_code="fr",@@ -6396,7 +6410,7 @@ def translated_product_unique_attribute_value(product, rich_text_attribute):product_type.product_attributes.add(rich_text_attribute)attribute_value = rich_text_attribute.values.first()associate_attribute_values_to_instance(- product, rich_text_attribute, attribute_value+ product, {rich_text_attribute.id: [attribute_value]})return AttributeValueTranslation.objects.create(language_code="fr",@@ -6411,7 +6425,7 @@ def translated_variant_unique_attribute_value(variant, rich_text_attribute):product_type.variant_attributes.add(rich_text_attribute)attribute_value = rich_text_attribute.values.first()associate_attribute_values_to_instance(- variant, rich_text_attribute, attribute_value+ variant, {rich_text_attribute.id: [attribute_value]})return AttributeValueTranslation.objects.create(language_code="fr",diff --git a/saleor/webhook/tests/test_webhook_serializers.py b/saleor/webhook/tests/test_webhook_serializers.pyindex a42f0c6e91..e77f4caf1f 100644--- a/saleor/webhook/tests/test_webhook_serializers.py+++ b/saleor/webhook/tests/test_webhook_serializers.py@@ -83,7 +83,7 @@ def test_serialize_product_attributes(attr_val_1 = AttributeValue.objects.create(attribute=attribute, name="Eco Mode", slug="eco")- associate_attribute_values_to_instance(product, attribute, attr_val_1)+ associate_attribute_values_to_instance(product, {attribute.id: [attr_val_1]})# product referenceproduct_slug = f"{product.pk}"@@ -94,7 +94,7 @@ def test_serialize_product_attributes(reference_product=product,)associate_attribute_values_to_instance(- product, product_type_product_reference_attribute, attr_value+ product, {product_type_product_reference_attribute.id: [attr_value]})# page reference@@ -107,12 +107,14 @@ def test_serialize_product_attributes(date_time=None,)associate_attribute_values_to_instance(- product, product_type_page_reference_attribute, ref_value+ product, {product_type_page_reference_attribute.id: [ref_value]})# filefile_attr_value = file_attribute.values.first()- associate_attribute_values_to_instance(product, file_attribute, file_attr_value)+ associate_attribute_values_to_instance(+ product, {file_attribute.id: [file_attr_value]}+ )# whenproduct_data = serialize_product_attributes(product)