Repository navigation
fix(i18n): stop f-strings in gettext leaking a bogus msgid on Python 3.12 - #44584
Conversation
…3.12 Two annotation-layer error messages in QueryContextProcessor passed an f-string to `_()`. On Python 3.11 babel's extractor skips an f-string entirely, but under Python 3.12 (PEP 701) the f-string is tokenized into parts and babel picks up the dict-key literals inside the replacement fields, extracting a nonsense msgid "valuename". The committed messages.pot is generated on 3.11, so the pot-drift test failed on the Python 3.12 unit-test leg that only runs on master pushes. Use parameterized gettext instead, which also makes the messages translatable for the first time, and regenerate messages.pot. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Code Review Agent Run #2f8a80Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #44584 +/- ##
=======================================
Coverage 81.06% 81.06%
=======================================
Files 2955 2955
Lines 178319 178319
Branches 41312 41312
=======================================
+ Hits 144549 144556 +7
+ Misses 31060 31052 -8
- Partials 2710 2711 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
EnxDev
left a comment
There was a problem hiding this comment.
Nice find on the PEP 701 tokenizer change, that explains the stray valuename showing up in other PRs' regenerated pots too. The parameterized messages and the tests asserting the rendered text look right to me.
One small note inline about what INT001 actually covers.
| "I", | ||
| # f-strings passed to gettext are never translatable, and on Python | ||
| # 3.12+ babel extracts bogus msgids from their replacement fields. | ||
| "INT001", |
There was a problem hiding this comment.
INT001 only checks _, gettext and ngettext by default, so __(f"...") still slips through, even though __ is one of the -k keywords babel extracts. I checked it with ruff --select INT001 on a scratch file.
Nothing in superset/ uses __ that way at the moment, so it's not blocking. Worth adding extend-function-names = ["__"] under [tool.ruff.lint.flake8-gettext] so the guard matches what babel extracts?
|
Adding |
rusackas
left a comment
There was a problem hiding this comment.
LGTM, and good catch tracing this to the PEP 701 tokenizer change. This is exactly what's been intermittently failing master's check_pot_drift_test.py — I'd chased it down to the value/name f-string interpolations here myself and was about to misdiagnose it as a parallel-worker race before finding this PR. Confirmed EnxDev's __(f"...") gap doesn't affect anything currently in the tree, so that's a fine non-blocking follow-up. Merging.
|
Bito Automatic Review Skipped – PR Already Merged |
The `next` Python-version leg (unit-tests matrix) ran on every push to master/release branches, exercising Python 3.12. Moves it to a dedicated nightly workflow instead so cross-version breakage is still caught, without paying for a second full Python version on every merge. Also bumps `next`'s resolved version from 3.12 to 3.13: the last 9 open code-scanning alerts against the base image's Python interpreter only have fix versions on 3.13+/3.14+, never backported to 3.11.x. This canary is the first step toward eventually bumping the Dockerfile's PY_VER off the 3.11 line -- it exists to surface any 3.13 incompatibilities (dependency or language-semantics, e.g. the PEP 701 f-string/babel break #44584 hit on 3.12) ahead of that, not to make the bump itself. Co-Authored-By: Evan Rusackas <[email protected]> Co-Authored-By: Claude Sonnet 5 <[email protected]>
The `next` Python-version leg (unit-tests matrix) ran on every push to master/release branches, exercising Python 3.12. Moves it to a dedicated nightly workflow instead so cross-version breakage is still caught, without paying for a second full Python version on every merge. Also bumps `next`'s resolved version from 3.12 to 3.13: the last 9 open code-scanning alerts against the base image's Python interpreter only have fix versions on 3.13+/3.14+, never backported to 3.11.x. This canary is the first step toward eventually bumping the Dockerfile's PY_VER off the 3.11 line -- it exists to surface any 3.13 incompatibilities (dependency or language-semantics, e.g. the PEP 701 f-string/babel break #44584 hit on 3.12) ahead of that, not to make the bump itself. Co-Authored-By: Evan Rusackas <[email protected]> Co-Authored-By: Claude Sonnet 5 <[email protected]>
The `next` Python-version leg (unit-tests matrix) ran on every push to master/release branches, exercising Python 3.12. Moves it to a dedicated nightly workflow instead so cross-version breakage is still caught, without paying for a second full Python version on every merge. Also bumps `next`'s resolved version from 3.12 to 3.13: the last 9 open code-scanning alerts against the base image's Python interpreter only have fix versions on 3.13+/3.14+, never backported to 3.11.x. This canary is the first step toward eventually bumping the Dockerfile's PY_VER off the 3.11 line -- it exists to surface any 3.13 incompatibilities (dependency or language-semantics, e.g. the PEP 701 f-string/babel break #44584 hit on 3.12) ahead of that, not to make the bump itself. Co-Authored-By: Evan Rusackas <[email protected]> Co-Authored-By: Claude Sonnet 5 <[email protected]>
…3.12 (#44584) Co-authored-by: Claude Opus 5.5 <[email protected]> (cherry picked from commit 390bf29)
Native run of scripts/translations/babel_update.sh after the second backport pass. Picks up the parameterized annotation-chart query-context message (#44584) and the impersonation-lookup error (#44653), whose master-side messages.pot hunks conflicted and were resolved to 7.0's side, and propagates every newly backported msgid into the .po catalogs.
SUMMARY
Python-Unithas been red on master because theunit-tests (next)leg (Python 3.12, push-only) failscheck_pot_drift_test.py::test_committed_template_matches_a_fresh_extraction:Root cause:
QueryContextProcessor.get_viz_annotation_datapassed two f-strings to_(). On Python 3.11 babel's extractor drops an f-string entirely. Under Python 3.12 (PEP 701) f-strings are tokenized into parts, and babel collects the dict-key literals inside the replacement fields (annotation_layer["value"],annotation_layer["name"]) and concatenates them into the msgid"valuename"(the second site yields"name", which is hidden because that msgid already exists).messages.potis generated on 3.11, so the drift check only disagrees on 3.12. PR CI only runs thecurrentPython leg, so this slipped through when the drift test was added in #44467.Fix: use parameterized gettext (
%(chart_id)s,%(layer_name)s) at both sites, which also makes these messages translatable for the first time (an f-string msgid can never match a catalog entry), and regeneratemessages.pot. These were the only_(f"...")calls insuperset/. The.pocatalogs are left to the regular translation sync to keep this diff minimal.Prevent recurrence: enable ruff
INT001(f-string passed to gettext). It flags both of the original call sites and has no other hits in the repo, so a new_(f"...")fails lint on every Python version instead of surfacing only in the push-only 3.12 leg.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
PR CI runs only the Python 3.11 leg, so here is the failing Python 3.12 leg reproduced locally (Python 3.12.13, babel 2.17.0, same test file master CI runs).
Before (master at 082961b, matching the failing
unit-tests (next)job on master):After (this branch):
TESTING INSTRUCTIONS
PR CI only runs Python 3.11, so it will not exercise the failing leg. Verified locally:
python scripts/translations/check_pot_drift.pyreports the template matches a fresh extraction, andpytest tests/unit_tests/scripts/translations/check_pot_drift_test.pypasses (7 passed)check_pot_drift.diff()returnsmissing=set(), stale=set()(before the fix:missing={'valuename'}), andpytest tests/unit_tests/scripts/translations/check_pot_drift_test.pypasses (7 passed)ruff check .passes withINT001enabled;INT001reports both sites when run against the pre-fix filetests/unit_tests/common/test_query_context_processor.pyassert the rendered text of both error messagesADDITIONAL INFORMATION
🤖 Generated with Claude Code