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

Second-level nested InlinePanel child objects are not copied for translation #809

Open
gasman opened this issue Jul 18, 2024 · 0 comments
Open
Labels
type:bug Something isn't working

Comments

@gasman
Copy link
Contributor

gasman commented Jul 18, 2024

If a snippet model definition contains two nested levels of InlinePanel children, then copying an item for translation results in the grandchild objects being moved from the source record to the translated record, instead of being copied.

Starting with a fresh Wagtail 6.2a0 instance with wagtail-localize installed and configured as

WAGTAIL_I18N_ENABLED = True
WAGTAIL_CONTENT_LANGUAGES = LANGUAGES = [
    ("en", "English"),
    ("fr", "French"),
]

and home/models.py as follows:

from django.db import models

from modelcluster.fields import ParentalKey
from modelcluster.models import ClusterableModel
from wagtail.admin.panels import FieldPanel, InlinePanel
from wagtail.models import Page, TranslatableMixin
from wagtail.snippets.models import register_snippet


class HomePage(Page):
    pass


@register_snippet
class Event(TranslatableMixin, ClusterableModel):
    name = models.CharField(max_length=255)

    def __str__(self):
        return self.name

    panels = [
        FieldPanel('name'),
        InlinePanel('sessions', label="Sessions"),
    ]


class Session(TranslatableMixin, ClusterableModel):
    event = ParentalKey(Event, related_name='sessions')
    name = models.CharField(max_length=255)

    def __str__(self):
        return self.name

    panels = [
        FieldPanel('name'),
        InlinePanel('speakers', label="Speakers"),
    ]


class Speaker(TranslatableMixin, models.Model):
    session = ParentalKey(Session, related_name='speakers')
    name = models.CharField(max_length=255)

    def __str__(self):
        return self.name

    panels = [
        FieldPanel('name'),
    ]
  • Add French as a locale
  • Create an Event snippet with name = Christmas, session name = Christmas Day, speaker name = Santa Claus
  • Check the database and note the ID of the created record in home_speaker
  • From the snippet listing, select Translate -> French, enter translations ("Noël", "le jour de Noël", "Père Noël"), then "Publish in French"
  • The original English event is now missing the record for Santa Claus
  • Checking the database again shows that the original record in home_speaker has been updated with the translation and attached to the new Session record, instead of being copied.
@zerolab zerolab added the type:bug Something isn't working label Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants