wagtail-localize
wagtail-localize copied to clipboard
Snippets with unique=true fields not translating
- Django 3.2.6
- Wagtail 2.14.1
- Wagtail-localize 1.0.0
I've replicated the bug on 2 sites with different models include clusterable and standard models.
When a field has unique=true, trying to make a translation seems successful but no translated copy of the snippet is made.
When hovering the mouse over the snippet instance, Translate button is still visible as well as the Sync Translated Snippets button:

Clicking the Sync button will produce an unhandled error:
DoesNotExist at /admin/localize/update/23/
TemplateText matching query does not exist.
When I still had wagtail-localize 0.9.5, trying to translate would throw an Integrity Error:
IntegrityError at /admin/localize/submit/snippet/site_settings/templatetext/21/
duplicate key value violates unique constraint "site_settings_templatetext_template_set_0baf3836_uniq"
DETAIL: Key (template_set)=(translatetest) already exists.
Discussed in https://github.com/wagtail/wagtail-localize/discussions/483
Originally posted by enzedonline November 4, 2021 Not sure if this is a question or a bug ...
I've added a second locale to a site I'm working on, everything translates fine except one snippet class. I get an IntegrityError whenever I try to translate one of these snippets, regardless of whether it was existing pre-locale addition or new since.
It's a clusterable model with orderables, simple class, nothing special going on, it's just a method to drop translated static text into non-Wagtail pages on the site.
The only thing I can think of is that the clusterable model has no translatable fields (ie translatable_fields = []), the translatable fields are in the child orderable class. Would this trip this error?
I have another clusertable/orderable snippet class that translates fine, so this is the only real difference I see between the two.
The error I receive on a brand new instance with no orderable yet saved (makes no difference to the error, just eliminating possible causes):
IntegrityError at /admin/localize/submit/snippet/site_settings/templatetext/21/
duplicate key value violates unique constraint "site_settings_templatetext_template_set_0baf3836_uniq"
DETAIL: Key (template_set)=(translatetest) already exists.
Request Method: POST
http://localhost/admin/localize/submit/snippet/site_settings/templatetext/21/?next=%2Fadmin%2Fsnippets%2Fsite_settings%2Ftemplatetext%2F
3.2.6
IntegrityError
duplicate key value violates unique constraint "site_settings_templatetext_template_set_0baf3836_uniq" DETAIL: Key (template_set)=(translatetest) already exists.
The snippet models:
class TemplateText(TranslatableMixin, ClusterableModel):
template_set = models.CharField(
unique=True,
max_length=50,
verbose_name="Set Name",
help_text=_("The set needs to be loaded in template tags then text references as {{set.tag}}")
)
translatable_fields = []
panels = [
FieldPanel("template_set"),
MultiFieldPanel(
[
InlinePanel("templatetext_items"),
],
heading=_("Text Items"),
),
]
def __str__(self):
return self.template_set
class Meta:
verbose_name = _('Template Text')
unique_together = ('translation_key', 'locale')
class TemplateTextSetItem(TranslatableMixin, Orderable):
set = ParentalKey(
"TemplateText",
related_name="templatetext_items",
help_text=_("Template Set to which this item belongs."),
verbose_name="Set Name",
)
template_tag = models.SlugField(
max_length=50,
help_text=_("Enter a tag without spaces, consisting of letters, numbers, underscores or hyphens."),
verbose_name="Template Tag",
)
text = models.TextField(
null=True,
blank=True,
help_text=_("The text to be inserted in the template.")
)
translatable_fields = [
TranslatableField('text'),
]
panels = [
RegexPanel('template_tag', '^[-\w]+$'),
FieldPanel('text'),
]
def __str__(self):
return self.template_tag
Any help greatly appreciated!
Django 3.2.6 Wagtail 2.14.1 Wagtail-localize 0.9.5
Related: #233