Repository navigation
fix(editor): tolerate stale review state from browser Back when same author - #23018
Conversation
…author The initial_state check introduced in dbdc688 (WeblateOrg#22292) rejects a form whose review state does not match the current unit state. Unlike the older translationsum check, it had no exemption for repeated edits by the same author. This caused a false "review state has changed" error when a translator saved a string, navigated Back, and re-saved from the browser-cached form. Apply the same same-author exemption: when the last content change was by the current user, clear initial_state so neither the form nor the downstream prepare_translation_update rejects the stale value. Refs WeblateOrg#22918
There was a problem hiding this comment.
All reported issues were addressed across 3 files
Reply to a comment to ask cubic a question or push back. It learns from your replies.
Re-trigger cubic
Set initial_state to unit.state instead of None so the optimistic concurrency check remains active for same-author repeated saves. Add state assertion to test_state_conflict_same_author_allowed.
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5263d66af0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| last_author = unit.get_last_content_change()[0] | ||
| if last_author == self.user: | ||
| self.cleaned_data["initial_state"] = unit.state |
There was a problem hiding this comment.
Check the review-state actor rather than the content author
When reviewer B accepts and approves a suggestion written by reviewer A, Suggestion.accept() records B as Change.user but A as Change.author. get_last_content_change() returns the latter, so if A still has an older editor form open, this branch incorrectly treats B's state change as A's own and replaces the expected state. A's stale save can then silently undo B's approval instead of reporting a conflict. Base the exemption on the actor of the actual state-changing history entry, not its content author.
AGENTS.md reference: AGENTS.md:L65-L66
Useful? React with 👍 / 👎.
| self.change_unit("Nazdar svete!\n", state=STATE_TRANSLATED, user=self.user) | ||
| response = self.client.post(self.url, self.data) | ||
| self.assertEqual(response.status_code, 302) |
There was a problem hiding this comment.
Update the remaining same-user conflict tests
The existing test_conflict_with_still_available_choice, test_zen_state_conflict, and Selenium's test_zen_review_state_conflict still expect same-user state changes to produce conflicts. The first two use change_unit() without an actor, which defaults to self.user; the Selenium test explicitly passes the logged-in user at weblate/trans/tests/test_selenium.py:2613. These submissions now succeed under the new exemption, so the unit tests fail their conflict assertions and the Selenium test times out waiting for a conflict toast. Use another user for those competing changes, or update their expectations to match the intended same-user behavior.
Useful? React with 👍 / 👎.
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
There is one pylint warning to fix (and it might show up as failed test as well). |
|
Thanks for the review. Fixed the pylint warning in 1b08365 — the Also merged main in 3501bf8 to resolve the merge conflict; all checks are passing now. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3501bf82d4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Merged, thanks for your contribution! |
What was broken
Translating an empty string, clicking "Save and continue", using the browser Back button, then editing and re-saving produces a false error:
The editor is stuck and the save is rejected.
Root cause
Commit dbdc688 (#22292) added an
initial_statecheck inTranslationForm.clean()to detect stale review states. The oldertranslationsumcheck already had a same-author exemption (last_author != self.user) so that re-saving your own work from a browser-cached form is tolerated. The newinitial_statecheck did not have the same exemption, so the user's own state change (empty → translated) is treated as a concurrent conflict.What changed
In
weblate/trans/forms.py, theinitial_statevalidation now checks whether the last content change was by the current user. If so, the staleinitial_stateis cleared (set toNone) so neither the form check nor the downstreamprepare_translation_updaterejects the edit. When the state was changed by a different user, the existing conflict error is still raised.Updated
test_state_conflict_preserves_draftto test only the other-user case, and addedtest_state_conflict_same_author_allowedto verify the same-user case now succeeds. Added a line todocs/changes.rstunder bug fixes.How I tested
ruff checkandruff formatpass on both changed files.Refs #22918