Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Slug generated from nase shouldnt use unicode (#10744)
Filip Owczarekcc5008ad7c06
diff --git a/saleor/core/tests/test_core.py b/saleor/core/tests/test_core.pyindex 220c4350a9..e9515fe74a 100644--- a/saleor/core/tests/test_core.py+++ b/saleor/core/tests/test_core.py@@ -242,8 +242,10 @@ def test_delete_sort_order_with_null_value(menu_item):("Shirt", "shirt"),("40.5", "405-2"),("FM1+", "fm1-2"),- ("زيوت", "زيوت"),- ("わたし-わ にっぽん です", "わたし-わ-にっぽん-です-2"),+ ("Ładny", "ladny"),+ ("زيوت", "zywt"),+ ("わたし-わ にっぽん です", "watasi-wa-nitupon-desu-2"),+ ("Салеор", "saleor-2"),],)def test_generate_unique_slug_with_slugable_field(@@ -253,9 +255,10 @@ def test_generate_unique_slug_with_slugable_field(("Paint", "paint"),("Paint blue", "paint-blue"),("Paint test", "paint-2"),+ ("Saleor", "saleor"),("405", "405"),("FM1", "fm1"),- ("わたし わ にっぽん です", "わたし-わ-にっぽん-です"),+ ("わたし わ にっぽん です", "watasi-wa-nitupon-desu"),]for name, slug in product_names_and_slugs:ProductType.objects.create(diff --git a/saleor/core/utils/__init__.py b/saleor/core/utils/__init__.pyindex 246f14411b..e048e16c5b 100644--- a/saleor/core/utils/__init__.py+++ b/saleor/core/utils/__init__.py@@ -12,6 +12,7 @@ from django.utils.encoding import iri_to_urifrom django.utils.text import slugifyfrom django_prices_openexchangerates import exchange_currencyfrom prices import MoneyRange+from text_unidecode import unidecodetask_logger = get_task_logger(__name__)@@ -114,7 +115,7 @@ def generate_unique_slug(with the same slug that passed also additional conditions"""- slug = slugify(slugable_value, allow_unicode=True)+ slug = slugify(unidecode(slugable_value))unique_slug: Union["SafeText", str] = slugModelClass = instance.__class__diff --git a/saleor/graphql/attribute/mutations.py b/saleor/graphql/attribute/mutations.pyindex ba16b0faec..3093dc19b5 100644--- a/saleor/graphql/attribute/mutations.py+++ b/saleor/graphql/attribute/mutations.py@@ -5,6 +5,7 @@ from django.core.exceptions import ObjectDoesNotExist, ValidationErrorfrom django.db import transactionfrom django.db.models import Exists, OuterRef, Q, Subqueryfrom django.utils.text import slugify+from text_unidecode import unidecodefrom ...attribute import ATTRIBUTE_PROPERTIES_CONFIGURATION, AttributeInputTypefrom ...attribute import models as models@@ -332,7 +333,7 @@ class AttributeMixin:cls.validate_swatch_attr_value(value_data)slug_value = value if not is_numeric_attr else value.replace(".", "_")- value_data["slug"] = slugify(slug_value, allow_unicode=True)+ value_data["slug"] = slugify(unidecode(slug_value))attribute_value = models.AttributeValue(**value_data, attribute=attribute)try:@@ -390,7 +391,7 @@ class AttributeMixin:# Check values uniqueness in case of creating new attribute.existing_values = attribute.values.values_list("slug", flat=True)for value_data in values_input:- slug = slugify(value_data["name"], allow_unicode=True)+ slug = slugify(unidecode(value_data["name"]))if slug in existing_values:msg = ("Value %s already exists within this attribute."@@ -405,8 +406,7 @@ class AttributeMixin:)new_slugs = [- slugify(value_data["name"], allow_unicode=True)- for value_data in values_input+ slugify(unidecode(value_data["name"])) for value_data in values_input]if len(set(new_slugs)) != len(new_slugs):raise ValidationError(diff --git a/saleor/graphql/attribute/utils.py b/saleor/graphql/attribute/utils.pyindex ac0413ad98..b9e00496ae 100644--- a/saleor/graphql/attribute/utils.py+++ b/saleor/graphql/attribute/utils.py@@ -13,6 +13,7 @@ from django.template.defaultfilters import truncatecharsfrom django.utils import timezonefrom django.utils.text import slugifyfrom graphql.error import GraphQLError+from text_unidecode import unidecodefrom ...attribute import AttributeEntityType, AttributeInputType, AttributeTypefrom ...attribute import models as attribute_models@@ -339,7 +340,7 @@ class AttributeAssignmentMixin:return tuple(get_or_create(attribute=attribute,- slug=slugify(value, allow_unicode=True),+ slug=slugify(unidecode(value)),defaults={"name": value},)[0]for value in attr_values.values@@ -404,7 +405,7 @@ class AttributeAssignmentMixin:boolean = bool(attr_values.boolean)value, _ = get_or_create(attribute=attribute,- slug=slugify(f"{attribute.id}_{boolean}", allow_unicode=True),+ slug=slugify(unidecode(f"{attribute.id}_{boolean}")),defaults={"name": f"{attribute.name}: {'Yes' if boolean else 'No'}","boolean": boolean,@@ -446,7 +447,7 @@ class AttributeAssignmentMixin:value_defaults: dict,):update_or_create = attribute.values.update_or_create- slug = slugify(f"{instance.id}_{attribute.id}", allow_unicode=True)+ slug = slugify(unidecode(f"{instance.id}_{attribute.id}"))value, _created = update_or_create(attribute=attribute,slug=slug,@@ -481,10 +482,7 @@ class AttributeAssignmentMixin:reference_list.append(get_or_create(attribute=attribute,- slug=slugify(- f"{instance.id}_{ref.id}", # type: ignore- allow_unicode=True,- ),+ slug=slugify(unidecode(f"{instance.id}_{ref.id}")), # type: ignoredefaults={"name": name},**{attr_value_field: ref},)[0]diff --git a/saleor/graphql/product/tests/test_category.py b/saleor/graphql/product/tests/test_category.pyindex f4fd0858c3..c03cac64b3 100644--- a/saleor/graphql/product/tests/test_category.py+++ b/saleor/graphql/product/tests/test_category.py@@ -543,7 +543,7 @@ def test_create_category_name_with_unicode(data = content["data"]["categoryCreate"]assert not data["errors"]assert data["category"]["name"] == name- assert data["category"]["slug"] == "わたし-わ-にっぽん-です"+ assert data["category"]["slug"] == "watasi-wa-nitupon-desu"def test_category_create_mutation_without_background_image(diff --git a/saleor/graphql/product/tests/test_collection.py b/saleor/graphql/product/tests/test_collection.pyindex cafe847c9b..479370dbac 100644--- a/saleor/graphql/product/tests/test_collection.py+++ b/saleor/graphql/product/tests/test_collection.py@@ -600,7 +600,7 @@ def test_create_collection_name_with_unicode(data = content["data"]["collectionCreate"]assert not data["errors"]assert data["collection"]["name"] == name- assert data["collection"]["slug"] == "わたし-わ-にっぽん-です"+ assert data["collection"]["slug"] == "watasi-wa-nitupon-desu"@patch("saleor.plugins.manager.PluginsManager.collection_updated")diff --git a/saleor/graphql/product/tests/test_product_type_create.py b/saleor/graphql/product/tests/test_product_type_create.pyindex da6d8aedbf..4a735344b7 100644--- a/saleor/graphql/product/tests/test_product_type_create.py+++ b/saleor/graphql/product/tests/test_product_type_create.py@@ -468,7 +468,7 @@ def test_create_product_type_with_unicode_in_name(data = content["data"]["productTypeCreate"]assert not data["errors"]assert data["productType"]["name"] == name- assert data["productType"]["slug"] == "わたし-わ-にっぽん-です"+ assert data["productType"]["slug"] == "watasi-wa-nitupon-desu"assert data["productType"]["kind"] == kind