Commit ad81512
authored
fix(unit): preserve fuzzy state for formats without fuzzy support (#18421)
Consider the following: There is an **untranslated** unit in a file format that doesn't support
writing fuzzy state to the file. The project has been configured with approved only commit
policy. The unit is translated to a fuzzy state. As it is the first uncommitted change to
the unit, `unit.details["disk_state"]["state"]"` will be updated and set to `STATE_EMPTY`.
`unit.state` is `STATE_FUZZY`. There is a `PendingUnitChange` in the database to commit the
translation to disk.
When a file sync is triggered, it attempts a commit. The pending change above is not committed
because it is not approved and nothing changes so far. During file sync, `Unit.update_from_unit`
is called on this unit which in turn calls `Unit.get_unit_state` to get current unit state.
`unit.state` is `STATE_FUZZY` so `unit.is_fuzzy(fallback=True)` is called.
https://github.com/WeblateOrg/weblate/blob/370adc360759d3453598eb0b3b4074539093456a/weblate/trans/models/unit.py#L857-L858
JSON format is not `SUPPORTS_FUZZY` so the fallback is returned directly.
https://github.com/WeblateOrg/weblate/blob/370adc360759d3453598eb0b3b4074539093456a/weblate/formats/ttkit.py#L158-L166
As a result, `Unit.get_unit_state` returns `STATE_FUZZY`. `comparison_state["state"]` is STATE_EMPTY.
`same_state` evaluates to `False` and the pending change is deleted from the database.
https://github.com/WeblateOrg/weblate/blob/370adc360759d3453598eb0b3b4074539093456a/weblate/trans/models/unit.py#L1102
* check whether unit is empty in `is_fuzzy`1 parent d216403 commit ad81512
3 files changed
+46
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
| 162 | + | |
| 163 | + | |
162 | 164 | | |
163 | 165 | | |
164 | 166 | | |
165 | | - | |
| 167 | + | |
166 | 168 | | |
167 | 169 | | |
168 | 170 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
20 | 25 | | |
21 | 26 | | |
22 | 27 | | |
| |||
809 | 814 | | |
810 | 815 | | |
811 | 816 | | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
812 | 852 | | |
813 | 853 | | |
814 | 854 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
339 | | - | |
340 | | - | |
| 339 | + | |
| 340 | + | |
341 | 341 | | |
342 | 342 | | |
343 | 343 | | |
| |||
0 commit comments