Skip to content

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

Prevent slug duplication when different instances got same PK (#17544)

Filip Owczarekc738dcc49f65
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.py
index bf5a6d5ad0..d267d25bba 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
@@ -332,13 +332,13 @@ def test_get_products_data_for_specified_warehouses_channels_and_attributes(
product_page_ref_value = AttributeValue.objects.create(
attribute=product_type_page_reference_attribute,
reference_page=page_list[0],
- slug=f"{product.pk}_{page_list[0].pk}",
+ slug=f"product_{product.pk}_page_{page_list[0].pk}",
name=page_list[0].title,
)
variant_page_ref_value = AttributeValue.objects.create(
attribute=product_type_page_reference_attribute,
reference_page=page_list[1],
- slug=f"{variant_with_many_stocks.pk}_{page_list[1].pk}",
+ slug=f"variant_{variant_with_many_stocks.pk}_page_{page_list[1].pk}",
name=page_list[1].title,
)
associate_attribute_values_to_instance(
@@ -354,15 +354,15 @@ def test_get_products_data_for_specified_warehouses_channels_and_attributes(
attribute=product_type_product_reference_attribute,
reference_product=product_with_variant_with_two_attributes,
slug=(
- f"{variant_with_many_stocks.pk}"
- f"_{product_with_variant_with_two_attributes.pk}"
+ f"variant_{variant_with_many_stocks.pk}"
+ f"_product_{product_with_variant_with_two_attributes.pk}"
),
name=product_with_variant_with_two_attributes.name,
)
product_product_ref_value = AttributeValue.objects.create(
attribute=product_type_product_reference_attribute,
reference_product=product_with_image,
- slug=f"{product.pk}_{product_with_image.pk}",
+ slug=f"product_{product.pk}_product_{product_with_image.pk}",
name=product_with_image.name,
)
associate_attribute_values_to_instance(
@@ -378,13 +378,13 @@ def test_get_products_data_for_specified_warehouses_channels_and_attributes(
variant_variant_ref_value = AttributeValue.objects.create(
attribute=product_type_variant_reference_attribute,
reference_variant=variant,
- slug=(f"{variant_with_many_stocks.pk}_{variant.pk}"),
+ slug=(f"variant_{variant_with_many_stocks.pk}_variant_{variant.pk}"),
name=variant.name,
)
product_variant_ref_value = AttributeValue.objects.create(
attribute=product_type_variant_reference_attribute,
reference_variant=variant,
- slug=f"{product.pk}_{variant.pk}",
+ slug=f"product_{product.pk}_variant_{variant.pk}",
name=variant.name,
)
associate_attribute_values_to_instance(
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.py
index b567c3b894..91e0d4647c 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
@@ -177,7 +177,7 @@ def test_prepare_products_relations_data(
ref_value = AttributeValue.objects.create(
attribute=product_type_page_reference_attribute,
reference_page=page,
- slug=f"{product_with_image.pk}_{page.pk}",
+ slug=f"product_{product_with_image.pk}_page_{page.pk}",
name=page.title,
date_time=None,
)
@@ -568,7 +568,7 @@ def test_prepare_variants_relations_data(
page_ref_value = AttributeValue.objects.create(
attribute=product_type_page_reference_attribute,
reference_page=page,
- slug=f"{variant.pk}_{page.pk}",
+ slug=f"variant_{variant.pk}_page_{page.pk}",
name=page.title,
)
associate_attribute_values_to_instance(
@@ -579,7 +579,7 @@ def test_prepare_variants_relations_data(
product_ref_value = AttributeValue.objects.create(
attribute=product_type_product_reference_attribute,
reference_product=product,
- slug=f"{variant.pk}_{product.pk}",
+ slug=f"variant_{variant.pk}_page_{product.pk}",
name=product.name,
)
associate_attribute_values_to_instance(
diff --git a/saleor/csv/tests/export/products_data/utils.py b/saleor/csv/tests/export/products_data/utils.py
index 45646fd3b0..dcbbf4072f 100644
--- a/saleor/csv/tests/export/products_data/utils.py
+++ b/saleor/csv/tests/export/products_data/utils.py
@@ -66,7 +66,7 @@ def get_attribute_value(attribute, value_instance):
if attribute.input_type == AttributeInputType.FILE:
value = "http://mirumee.com/media/" + value_instance.file_url
elif attribute.input_type == AttributeInputType.REFERENCE:
- ref_id = value_instance.slug.split("_")[1]
+ ref_id = value_instance.slug.split("_")[3]
value = f"{attribute.entity_type}_{ref_id}"
elif attribute.input_type == AttributeInputType.NUMERIC:
value = f"{value_instance.name}"