Skip to content

fix(editor): tolerate stale review state from browser Back when same author - #23018

Merged
nijel merged 9 commits into
WeblateOrg:mainfrom
jo1-yo:fix/stale-review-state-22918
Nov 29, 2026
Merged

nijel merged 9 commits into
WeblateOrg:mainfrom
jo1-yo:fix/stale-review-state-22918

Conversation

@jo1-yo

@jo1-yo jo1-yo commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

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 review state of this string has changed from Empty to Waiting for review while you were editing it.

The editor is stuck and the save is rejected.

Root cause

Commit dbdc688 (#22292) added an initial_state check in TranslationForm.clean() to detect stale review states. The older translationsum check 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 new initial_state check 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, the initial_state validation now checks whether the last content change was by the current user. If so, the stale initial_state is cleared (set to None) so neither the form check nor the downstream prepare_translation_update rejects the edit. When the state was changed by a different user, the existing conflict error is still raised.

Updated test_state_conflict_preserves_draft to test only the other-user case, and added test_state_conflict_same_author_allowed to verify the same-user case now succeeds. Added a line to docs/changes.rst under bug fixes.

How I tested

  • ruff check and ruff format pass on both changed files.
  • Could not run the full pytest suite locally (no PostgreSQL available); CI will verify.

Refs #22918

…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
@jo1-yo
jo1-yo requested a review from nijel as a code owner November 21, 2026 01:21

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread weblate/trans/tests/test_edit.py Resolved
Comment thread weblate/trans/forms.py Resolved
jo1-yo and others added 2 commits November 21, 2026 14:23
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.
@nijel

nijel commented Nov 25, 2026

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T08:09:39.317540Z 3501bf8 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread weblate/trans/forms.py
Comment on lines +941 to +943
last_author = unit.get_last_content_change()[0]
if last_author == self.user:
self.cleaned_data["initial_state"] = unit.state

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment on lines +598 to +600
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@nijel nijel linked an issue Nov 26, 2026 that may be closed by this pull request
2 tasks done
@nijel nijel self-assigned this Nov 26, 2026
@nijel

nijel commented Nov 26, 2026

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 2f8393ecd8

ℹ️ 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".

@nijel

nijel commented Nov 26, 2026

Copy link
Copy Markdown
Member

There is one pylint warning to fix (and it might show up as failed test as well).

@nijel
nijel enabled auto-merge (squash) November 27, 2026 12:21
@jo1-yo

jo1-yo commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Fixed the pylint warning in 1b08365 — the user variable in test_zen_review_state_conflict was left over after switching the competing state change to other_user.

Also merged main in 3501bf8 to resolve the merge conflict; all checks are passing now.

@nijel

nijel commented Nov 29, 2026

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread weblate/trans/forms.py Resolved
@nijel
nijel disabled auto-merge November 29, 2026 12:03
@nijel
nijel merged commit d9360fa into WeblateOrg:main Nov 29, 2026
44 of 47 checks passed
@nijel

nijel commented Nov 29, 2026

Copy link
Copy Markdown
Member

Merged, thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect "The review state of this string has changed" using browser "Back" button

2 participants