wagtail-localize
wagtail-localize copied to clipboard
InlinePanel raises IntegrityError during save
Hello! I have two models EmployeeContact (snippet) and EmployeePage (Page) with InlinePanel, connected to the first model EmployeeContact All these models are localized and have more than 1 language
@register_snippet
class EmployeeContact(TranslatableMixin):
class Meta(TranslatableMixin.Meta):
verbose_name = _('employee contact')
type_of_contact = models.CharField(_('Type of contact'), max_length=255)
employee = ParentalKey(
'EmployeePage',
on_delete=models.PROTECT,
related_name='employee_contacts'
)
contact = models.CharField(_('Employee contact'), max_length=255)
class EmployeePage(Page):
name = models.CharField(_('Name'), max_length=255)
surname = models.CharField(_('Surname'), max_length=255)
job = models.CharField(_('Job title'), max_length=255)
content_panels = Page.content_panels + [
MultiFieldPanel(
[
FieldPanel('name'),
FieldPanel('surname'),
FieldPanel('job'),
],
heading=_('General'),
MultiFieldPanel(
[
InlinePanel('employee_contacts'),
],
heading=_('Personal employee contacts),
),
]
If I add EmployeeContact to existed EmployeePage - it's all okay, snippet is created and linked to EmployeePage But if I create EmployeePage with filled EmployeeContacts inline - I get IntegrityError
django.db.utils.IntegrityError: duplicate key value violates unique constraint "company_employeecontact_translation_key_locale_id_bb11fe2f_uniq" DETAIL: Key (translation_key, locale_id)=(4a531763-ecae-4a42-805e-9f2794ce0117, 5) already exists.
I can be wrong, but it can be caused by such situations - when I create EmployeePage in eng (main lang), it also creates in other lang, and it try to create snippet EmployeeContact only for locale EN for ALL pages - and of course it raises Integrity Error ??
Anyway THANKS!
Hey @ArthurConan,
I believe this should be fixed in the latest 2.15, 2.16, 3.0 Wagtail versions.
Related: https://github.com/wagtail/wagtail/pull/8161
Any chance you can double check?