Hi there and thanks for this great library.
I would like to draw your attention to this code here:
|
elif isinstance(translation, RevisionMixin): |
|
# We copied another instance which may be live, so we make sure this one matches the desired state |
|
translation.live = publish |
|
translation.save() |
|
|
|
# Create a new revision of the Snippet |
|
new_revision = translation.save_revision(user=user) |
|
|
|
if publish: |
|
transaction.on_commit(new_revision.publish) |
Taken from TranslationSource.create_or_update_translation.
Here a new translation is being saved. The code checks to see if the translated object is a RevisionMixin and if so it creates a new_revision and then publishes it.
Revision from wagtail.models defines a publish() method:
# wagtail/models/__init__.py
def publish(
self,
user=None,
changed=True,
log_action=True,
previous_revision=None,
skip_permission_checks=False,
):
return self.content_object.publish(
self,
user=user,
changed=changed,
log_action=log_action,
previous_revision=previous_revision,
skip_permission_checks=skip_permission_checks,
)
Note that it in turn calls self.content_object.publish, where self.content_object is essentially the translated object we started with.
The problem is that adding RevisionMixin to, say, a snippet does not give it a publish() method, so you get an AttributeError on self.content_object.
DraftStateMixin does provide a publish() method so snippets that have both drafts and revisions are fine but those with just revisions crash.
Something along the lines of the following might fix this:
elif isinstance(translation, RevisionMixin):
# We copied another instance which may be live, so we make sure this one matches the desired state
translation.live = publish
translation.save()
# Create a new revision of the Snippet
new_revision = translation.save_revision(user=user)
if publish and isinstance(translation, DraftStateMixin): # <--- extra check
transaction.on_commit(new_revision.publish)
Hi there and thanks for this great library.
I would like to draw your attention to this code here:
wagtail-localize/wagtail_localize/models.py
Lines 807 to 816 in 7797bd3
Taken from
TranslationSource.create_or_update_translation.Here a new translation is being saved. The code checks to see if the translated object is a
RevisionMixinand if so it creates a new_revision and then publishes it.Revisionfromwagtail.modelsdefines apublish()method:Note that it in turn calls
self.content_object.publish, whereself.content_objectis essentially the translated object we started with.The problem is that adding
RevisionMixinto, say, a snippet does not give it apublish()method, so you get anAttributeErroronself.content_object.DraftStateMixindoes provide apublish()method so snippets that have both drafts and revisions are fine but those with just revisions crash.Something along the lines of the following might fix this: