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
Use the latest draft for translation (#7754) #7755
Conversation
Manage this branch in SquashTest this branch here: https://gnomebygnomeby-patch-7754-bxtlm.squash.io |
@gnomeby thanks for taking the time to contribute a fix for #7754 - In principle this looks good but we will get another review from a core team member also. However, we ask that you take a bit more time to contribute a unit test that covers this scenario with the fix. This way it will be much harder to break this in the future. |
OK, I'll add them. |
@gnomeby Thank you for your contribution to Wagtail. The code looks sound. However, I doubt this is the desired behaviour. Why is copying the last revision more correct than copying the current page? Copying the last revision might come as a surprise to some users. Or am I missing something? Is there a scenario I did not consider? Why is the the latest revision a better source for a translation than the current page? Revisions are the last 'draft' saved by anyone. That doesn't mean the content is more correct than the current page. The revision might be a rough -and failed- rewrite of the page. That should not be published. Ever. Let alone be translated. I consider the current page as the most correct content. The content most suitable to be translated. TLDR; The latest revision doesn't have to be 'more correct' than current page. I'm not 100% sure about my own argumentation, so I'm happy to convinced otherwise. FYI, simple translation is a perfect starting point for your own translation app. Copy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think last revision is 'better' content than the current page. A revision might even be a failed draft. Therefore not a suitable source for translations.
I think this might be related to the common "gotcha" with pages that have never been published, seen most recently in #7690 (comment) - if a page has never been published, then the 'live' page record will reflect the state of the page when it was first created and saved for the first time - subsequent 'save draft' actions will only affect page revisions, so it will never move on from that state. In this case, the outcome is less desirable (and more surprising) than selecting the latest draft revision. Detecting pages that have never been published is a bit of a black art, so I'd suggest that we also select the latest draft for pages that were published and then unpublished. (In these cases, the 'live' page record will be frozen at the last published version, which may be far out of date.) In other words - when copying a page for translation, I'd suggest the following logic:
|
@gasman agree |
I've updated PR using @gasman advice |
There has been some more recent work on how non-saved drafts are treated. This needs some rework and maybe some discussion before it's able to be reviewed again. Flagging as needs work / needs design decision. |
@@ -146,7 +148,11 @@ def execute(self, skip_permission_checks=False): | |||
self.check(skip_permission_checks=skip_permission_checks) | |||
|
|||
translated_page = self._copy_for_translation( | |||
self.page, self.locale, self.copy_parents, self.alias, self.exclude_fields | |||
self.page.live and self.page or self.page.get_latest_revision_as_page(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.page if self.page.live else self.page.get_latest_revision_as_page()
is the more familiar syntax I think, but happy with this logic.
Fix for #7754
Thanks for contributing to Wagtail! 🎉
Before submitting, please review the contributor guidelines https://docs.wagtail.io/en/latest/contributing/index.html and check the following:
make lint
from the Wagtail root)