Skip to content

Re-parse Fluent values left stale by the moz.l10n 0.15.0 update - #4705

Open
matthewalberto wants to merge 1 commit into
mozilla:mainfrom
matthewalberto:fix-4699-reparse-stale-fluent-values
Open

matthewalberto wants to merge 1 commit into
mozilla:mainfrom
matthewalberto:fix-4699-reparse-stale-fluent-values

Conversation

@matthewalberto

Copy link
Copy Markdown
Contributor

Fixes #4699

The source entities and translations of some Fluent strings still hold a value in the shape moz.l10n produced before 0.15.0 (sel: ['hours_1'], a fluent-fn: NUMBER attribute on a plain placeholder). A fresh parse of the same string gives sel: ['hours'] and no attribute. When an editor saves a translation it copies that old shape, so the next sync sees a different value, creates a second approved translation with the same string and rejects the editor's one.

#4611 changed the parse output without a migration, so this adds one in the same way as 0122_reparse_multi_pattern_fluent and 0135_fix_fluent_function_names. It is migration-only, as asked on the issue: translations_equal is not touched.

What the migration does:

  • Re-parses every Fluent Entity and Translation whose string contains a {, because only a message with an expression can have a changed shape.
  • Writes a row only when its stored value or properties differ from the fresh parse, in batches of 1000.
  • Skips, with a warning, a row whose string the parser rejects, like 0135 does.
  • Has a no-op reverse, as 0135 does.

Testing:

  • Two new tests in pontoon/base/tests/migrations/test_reparse_stale_fluent_values.py. One makes an entity and a translation stale in the shape from the issue and checks both are rebuilt to the fresh parse. The other checks that an up-to-date Fluent entity, a Fluent entity with no expression, and a non-Fluent entity are left as they were.
  • I broke the migration three ways (entities never selected, translations never selected, the Fluent format filter dropped) and each one fails a test. Removing the "only write when different" check does not fail a test, since it only saves writes.
  • pytest pontoon/base/tests/migrations passes (3 tests) against PostgreSQL 16, and ruff check and ruff format --check are clean.

Not tested: a run against a production-sized database, so I can't say how long it takes there.

This branch has not been deployed

No deployments
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.

Sync replaces identical Fluent translation because of stale source value

1 participant