Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String segments resests after synchronizing translations #838

Open
Azadron228 opened this issue Dec 13, 2024 · 2 comments
Open

String segments resests after synchronizing translations #838

Azadron228 opened this issue Dec 13, 2024 · 2 comments

Comments

@Azadron228
Copy link

I am encountering an issue where some string segments reset after synchronizing and publishing translations. Specifically:

Only certain pages are affected, and within those pages, only some strings reset.
The resetting string segments are being re-inserted into the wagtail_localize_stringsegments table after synchronization.
Other pages and string segments of same page model work as expected without issues.

Environment:

wagtail-localize: 1.8
Django: 4.0.7
Wagtail: 5.2
Database: MySQL

This is how i created page

class ChairMemberPage(SitemapMixin, Page):
    parent_page_types = [ChairPage]

    photo = models.ForeignKey(
        "wagtailimages.Image",
        null=True,
        on_delete=models.SET_NULL,
        related_name="+",
        verbose_name="Фото",
    )
    position = models.CharField(max_length=100, verbose_name="Должность")
    email = models.EmailField(verbose_name="Электронная почта")
    subjects = RichTextField(verbose_name="Основные преподаваемые дисциплины")
    education = RichTextField(verbose_name="Образование")

    info = StreamField(
        [("paragraph", blocks.RichTextBlock(label="Параграф с доп. информацией"))],
        verbose_name="Дополнительная информация",
        blank=True,
        null=True,
        use_json_field=True,
    )

    content_panels = Page.content_panels + [
        FieldPanel("photo"),
        FieldPanel("position"),
        FieldPanel("email"),
        FieldPanel("subjects"),
        FieldPanel("education"),
        FieldPanel("info"),
    ]

    search_fields = Page.search_fields + [
        index.SearchField("position"),
        index.SearchField("email"),
        index.SearchField("subjects"),
        index.SearchField("education"),
        index.SearchField("info"),
    ]

    class Meta:
        verbose_name = "Сотрудник кафедры"
        verbose_name_plural = "Сотрудники кафедры"
@Azadron228
Copy link
Author

After further analysis, I identified the root cause of a data inconsistency issue during the synchronization process. The issue occurs because wagtail_localize_stringsegment entries are being reinserted instead of being retrieved from the database, and not all segments are inserted as expected. This leads to a mismatch between wagtail_localize_stringtranslation.translation_of_id and wagtail_localize_stringsegment.string_id.

This query run for almost all segments

INSERT INTO `wagtail_localize_stringsegment` (`source_id`, `context_id`, `order`, `string_id`, `attrs`) 
VALUES (1597, 16609, 52, 29431, 'null');

SQL Query to Retrieve Translations:

The following query retrieves translations for string segments:

SELECT
    `wagtail_localize_stringsegment`.`id`,
    `wagtail_localize_stringsegment`.`source_id`,
    `wagtail_localize_stringsegment`.`context_id`,
    `wagtail_localize_stringsegment`.`order`,
    `wagtail_localize_stringsegment`.`string_id`,
    `wagtail_localize_stringsegment`.`attrs`,
    (
        SELECT
            U0.`data`
        FROM
            `wagtail_localize_stringtranslation` U0
        WHERE
            U0.`context_id` = `wagtail_localize_stringsegment`.`context_id`
            AND U0.`locale_id` = 2
            AND U0.`translation_of_id` = `wagtail_localize_stringsegment`.`string_id` --at this line filtering fails
            AND NOT U0.`has_error`
    ) AS `translation`,
    `wagtail_localize_translationcontext`.`id`,
    `wagtail_localize_translationcontext`.`object_id`,
    `wagtail_localize_translationcontext`.`path_id`,
    `wagtail_localize_translationcontext`.`path`,
    `wagtail_localize_translationcontext`.`field_path`,
    `wagtail_localize_string`.`id`,
    `wagtail_localize_string`.`locale_id`,
    `wagtail_localize_string`.`data_hash`,
    `wagtail_localize_string`.`data`
FROM
    `wagtail_localize_stringsegment`
INNER JOIN `wagtail_localize_translationcontext`
    ON `wagtail_localize_stringsegment`.`context_id` = `wagtail_localize_translationcontext`.`id`
INNER JOIN `wagtail_localize_string`
    ON `wagtail_localize_stringsegment`.`string_id` = `wagtail_localize_string`.`id`
WHERE
    `wagtail_localize_stringsegment`.`source_id` = 1597;

@Azadron228
Copy link
Author

Wrong segment comes from extract_segments() which leads to data inconsistentcy, and recreation of string.

I have checked strings in database got two visually similar strings which differ in backspace which lead to bug.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant