Skip to content

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

Set the name on the bulk translated instance

Ania Warzechaa1ba6dacdbe0
diff --git a/saleor/attribute/migrations/0030_extend_attributr_value_fields_length.py b/saleor/attribute/migrations/0031_extend_attributr_value_fields_length.py
similarity index 93%
rename from saleor/attribute/migrations/0030_extend_attributr_value_fields_length.py
rename to saleor/attribute/migrations/0031_extend_attributr_value_fields_length.py
index 0e551481a8..90450e97a0 100644
--- a/saleor/attribute/migrations/0030_extend_attributr_value_fields_length.py
+++ b/saleor/attribute/migrations/0031_extend_attributr_value_fields_length.py
@@ -5,7 +5,7 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
- ("attribute", "0029_alter_attribute_unit"),
+ ("attribute", "0030_assignedproductattributevalue_product"),
]
operations = [
diff --git a/saleor/graphql/translations/mutations/attribute_value_bulk_translate.py b/saleor/graphql/translations/mutations/attribute_value_bulk_translate.py
index b4d2cf5597..159c593239 100644
--- a/saleor/graphql/translations/mutations/attribute_value_bulk_translate.py
+++ b/saleor/graphql/translations/mutations/attribute_value_bulk_translate.py
@@ -140,10 +140,16 @@ class AttributeValueBulkTranslate(BaseBulkTranslateMutation):
@classmethod
def pre_update_or_create(cls, instance, input_data):
if input_data.get("name") is None:
- if instance.attribute.input_type == AttributeInputType.RICH_TEXT:
+ attribute = instance.attribute_value.attribute
+ if attribute.input_type == AttributeInputType.RICH_TEXT:
input_data["name"] = truncatechars(
clean_editor_js(input_data["rich_text"], to_string=True), 250
)
- elif instance.attribute.input_type == AttributeInputType.PLAIN_TEXT:
+ elif attribute.input_type == AttributeInputType.PLAIN_TEXT:
input_data["name"] = truncatechars(input_data["plain_text"], 250)
+
+ # Set this value on the instance too as at this point it was already created
+ # input_data will be used for validation
+ # the value on the instance will be used to save it after the validation
+ instance.name = input_data["name"]
return input_data
diff --git a/saleor/graphql/translations/tests/mutations/test_attribute_value_bulk_transalte.py b/saleor/graphql/translations/tests/mutations/test_attribute_value_bulk_transalte.py
index 177fb937b1..3373660b9e 100644
--- a/saleor/graphql/translations/tests/mutations/test_attribute_value_bulk_transalte.py
+++ b/saleor/graphql/translations/tests/mutations/test_attribute_value_bulk_transalte.py
@@ -106,7 +106,6 @@ def test_attribute_value_bulk_translate_creates_name_from_translations_long_text
value = plain_text_attribute.values.first()
value_global_id = graphene.Node.to_global_id("AttributeValue", value.id)
expected_text = "Nowy Kolor" * 250
- expected_rich_text = json.dumps(dummy_editorjs(expected_text))
assert value.translations.count() == 0
@@ -128,7 +127,6 @@ def test_attribute_value_bulk_translate_creates_name_from_translations_long_text
)
content = get_graphql_content(response)
data = content["data"]["attributeValueBulkTranslate"]
- print(data["results"][0]["translation"])
# then
assert value.translations.count() == 1
@@ -136,7 +134,6 @@ def test_attribute_value_bulk_translate_creates_name_from_translations_long_text
assert data["count"] == 1
assert data["results"][0]["translation"]["name"] == expected_text[:249] + "…"
assert data["results"][0]["translation"]["plainText"] == expected_text
- assert data["results"][0]["translation"]["richText"] == expected_rich_text
assert created_webhook_mock.call_count == 1