Skip to content
Merged
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Weblate 2026.12

.. rubric:: Bug fixes

* Fixed a false review-state conflict when saving your own edit again after using the browser's Back button in the translation editor.
* Applied :ref:`enforced checks <enforcing-checks>` when changing a string's state through :ref:`bulk editing <bulk-edit>`.
* Preserved draft edits and explained how to save them when submitting a :ref:`suggestion <suggestions>` with changes to a glossary explanation.
* Preserved the :ref:`category hierarchy <category>` on project and category language overviews.
Expand Down
11 changes: 10 additions & 1 deletion weblate/trans/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,8 +932,17 @@ def clean(self) -> None:
initial_state is not None
and self.user_can_edit
and "suggest" not in self.data
and state_changed
):
unit.validate_review_state(initial_state)
# Allow repeated edits by the same author, matching the
# translationsum exemption above: when the user's own save
# changed the review state, tolerate the stale initial_state
# from a browser-cached form.
last_author = unit.get_last_content_change()[0]
if last_author == self.user:
self.cleaned_data["initial_state"] = None
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
else:
unit.validate_review_state(initial_state)

fuzzy_state = unit.state if unit.state in FUZZY_STATES else STATE_FUZZY

Expand Down
56 changes: 31 additions & 25 deletions weblate/trans/tests/test_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,31 +569,37 @@ def setUp(self) -> None:
}

def test_state_conflict_preserves_draft(self) -> None:
for actor in (self.user, self.anotheruser):
with self.subTest(actor=actor.username):
self.change_unit("Nazdar svete!\n", state=STATE_NEEDS_REWRITING)
self.change_unit("Nazdar svete!\n", state=STATE_TRANSLATED, user=actor)
change_count = Change.objects.filter(unit=self.unit).count()
for _attempt in range(2):
response = self.client.post(self.url, self.data)
self.assertContains(
response,
"The review state of this string has changed from "
"Needs editing (Needs rewriting) to Translated",
)
self.assertNotContains(
response, "This review state is not available"
)
self.assertNotContains(response, "Select a valid choice")
self.assertContains(response, self.data["target_0"])
self.assertContains(response, 'name="initial_state" value="11"')
self.assertContains(response, 'data-unsaved="true"')
self.unit.refresh_from_db()
self.assertEqual(self.unit.target, "Nazdar svete!\n")
self.assertEqual(self.unit.state, STATE_TRANSLATED)
self.assertEqual(
Change.objects.filter(unit=self.unit).count(), change_count
)
"""Another user changed the state: the stale form is rejected."""
self.change_unit("Nazdar svete!\n", state=STATE_NEEDS_REWRITING)
self.change_unit(
"Nazdar svete!\n", state=STATE_TRANSLATED, user=self.anotheruser
)
change_count = Change.objects.filter(unit=self.unit).count()
for _attempt in range(2):
response = self.client.post(self.url, self.data)
self.assertContains(
response,
"The review state of this string has changed from "
"Needs editing (Needs rewriting) to Translated",
)
self.assertNotContains(response, "This review state is not available")
self.assertNotContains(response, "Select a valid choice")
self.assertContains(response, self.data["target_0"])
self.assertContains(response, 'name="initial_state" value="11"')
self.assertContains(response, 'data-unsaved="true"')
self.unit.refresh_from_db()
self.assertEqual(self.unit.target, "Nazdar svete!\n")
self.assertEqual(self.unit.state, STATE_TRANSLATED)
self.assertEqual(Change.objects.filter(unit=self.unit).count(), change_count)

def test_state_conflict_same_author_allowed(self) -> None:
"""Same user changed the state (browser Back): the stale form is accepted."""
self.change_unit("Nazdar svete!\n", state=STATE_NEEDS_REWRITING)
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)
Comment on lines +598 to +600

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

self.unit.refresh_from_db()
self.assertEqual(self.unit.target, self.data["target_0"])
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved

def test_conflict_with_still_available_choice(self) -> None:
self.change_unit("Nazdar svete!\n", state=STATE_NEEDS_CHECKING)
Expand Down