wagtail / wagtail-localize

Translation plugin for Wagtail CMS
https://wagtail-localize.org/
Other
226 stars 86 forks source link

Translatable orderables return 500 error when publishing a copied page #632

Open danielfmiranda opened 2 years ago

danielfmiranda commented 2 years ago

When a user creates a copy of a wagtail page that uses a translatable snippet orderable, a 500 error regarding translation keys and locale id gets returned. I believe this is being caused by the snippet still using the alias of the original page.

Screenshot of error message:

IntegrityError at /cms/pages/19687/edit/
duplicate key value violates unique constraint "wagtailpages_blogauthors_translation_key_locale_i_d8e610e6_uniq"
DETAIL:  Key (translation_key, locale_id)=(1a0a5a33-d4b8-4121-84a4-9b34939910bb, 1) already exists.

Example:

In our application, BlogAuthors is an orderable using a snippet named Profile.

Profile Model Definition:

class Profile(TranslatableMixin, models.Model):
...

BlogAuthors Orderable Definition (Linked to wagtail page):

class BlogAuthors(TranslatableMixin, Orderable):

    page = ParentalKey('wagtailpages.BlogPage', related_name='authors')
    author = models.ForeignKey(
        Profile,
        on_delete=models.CASCADE,
    )

The orderable relationship is then set as a TranslateableField under the wagtail page:

TranslatableField('authors'),

When creating a copy of a page and attempting to publish it, the 500 error above then gets returned until we publish it with a different author, and then return and publish with the actual desired author.

zerolab commented 2 years ago

Also possibly related: #591

zerolab commented 2 years ago

As an aside, it may be a Wagtail core issue, a la https://github.com/wagtail/wagtail/pull/8161