Skip to content

fix(i18n): stop f-strings in gettext leaking a bogus msgid on Python 3.12 - #44584

Merged
rusackas merged 2 commits into
masterfrom
fix-master-unit-tests
Sep 23, 2026
Merged

rusackas merged 2 commits into
masterfrom
fix-master-unit-tests

Conversation

@sadpandajoe

@sadpandajoe sadpandajoe commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

SUMMARY

Python-Unit has been red on master because the unit-tests (next) leg (Python 3.12, push-only) fails check_pot_drift_test.py::test_committed_template_matches_a_fresh_extraction:

AssertionError: 1 string(s) in source missing from messages.pot
assert not {'valuename'}

Root cause: QueryContextProcessor.get_viz_annotation_data passed 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.pot is generated on 3.11, so the drift check only disagrees on 3.12. PR CI only runs the current Python 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 regenerate messages.pot. These were the only _(f"...") calls in superset/. The .po catalogs 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):

python3.12 -m pytest tests/unit_tests/scripts/translations/check_pot_drift_test.py
============================= test session starts ==============================
platform darwin -- Python 3.12.13, pytest-9.1.1, pluggy-1.6.0
configfile: pytest.ini
collected 7 items

tests/unit_tests/scripts/translations/check_pot_drift_test.py ......F    [100%]

=================================== FAILURES ===================================
______________ test_committed_template_matches_a_fresh_extraction ______________

>       assert not missing, f"{len(missing)} string(s) in source missing from messages.pot"
E       AssertionError: 1 string(s) in source missing from messages.pot
E       assert not {'valuename'}

tests/unit_tests/scripts/translations/check_pot_drift_test.py:155: AssertionError
=========================== short test summary info ============================
FAILED tests/unit_tests/scripts/translations/check_pot_drift_test.py::test_committed_template_matches_a_fresh_extraction
==================== 1 failed, 6 passed in 63.54s (0:01:03) ====================

After (this branch):

python3.12 -m pytest tests/unit_tests/scripts/translations/check_pot_drift_test.py
============================= test session starts ==============================
platform darwin -- Python 3.12.13, pytest-9.1.1, pluggy-1.6.0
configfile: pytest.ini
collected 7 items

tests/unit_tests/scripts/translations/check_pot_drift_test.py .......    [100%]

========================= 7 passed in 68.77s (0:01:08) =========================

TESTING INSTRUCTIONS

PR CI only runs Python 3.11, so it will not exercise the failing leg. Verified locally:

  • Python 3.11.9: python scripts/translations/check_pot_drift.py reports the template matches a fresh extraction, and pytest tests/unit_tests/scripts/translations/check_pot_drift_test.py passes (7 passed)
  • Python 3.12.13 (babel 2.17.0): check_pot_drift.diff() returns missing=set(), stale=set() (before the fix: missing={'valuename'}), and pytest tests/unit_tests/scripts/translations/check_pot_drift_test.py passes (7 passed)
  • ruff check . passes with INT001 enabled; INT001 reports both sites when run against the pre-fix file
  • New unit tests in tests/unit_tests/common/test_query_context_processor.py assert the rendered text of both error messages

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

🤖 Generated with Claude Code

…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]>
@bito-code-review

bito-code-review Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #2f8a80

Actionable Suggestions - 0
Review Details
  • Files reviewed - 3 · Commit Range: 2832e68..2832e68
    • superset/common/query_context_processor.py
    • superset/translations/messages.pot
    • tests/unit_tests/common/test_query_context_processor.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@github-actions github-actions Bot added the i18n Namespace | Anything related to localization label Sep 23, 2026
@codecov

codecov Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.06%. Comparing base (082961b) to head (ba86db2).
⚠️ Report is 1 commits behind head on master.

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     
Flag Coverage Δ
hive 36.80% <ø> (ø)
mysql 55.98% <ø> (+<0.01%) ⬆️
postgres 55.99% <ø> (+<0.01%) ⬆️
presto 38.70% <ø> (ø)
python 85.37% <ø> (+<0.01%) ⬆️
sqlite 55.71% <ø> (ø)
unit 77.64% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@EnxDev EnxDev 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.

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.

Comment thread pyproject.toml
"I",
# f-strings passed to gettext are never translatable, and on Python
# 3.12+ babel extracts bogus msgids from their replacement fields.
"INT001",

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.

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?

@bito-code-review

Copy link
Copy Markdown
Contributor

Adding extend-function-names = ["__"] to [tool.ruff.lint.flake8-gettext] is a recommended improvement to ensure consistency between Babel's extraction and Ruff's linting. Since __ is used as a keyword for translation, explicitly configuring Ruff to recognize it will prevent INT001 from missing these calls, even if it is not currently blocking any issues in the codebase.

@rusackas rusackas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@rusackas
rusackas merged commit 390bf29 into master Sep 23, 2026
102 checks passed
@rusackas
rusackas deleted the fix-master-unit-tests branch September 23, 2026 22:34
@bito-code-review

Copy link
Copy Markdown
Contributor

Bito Automatic Review Skipped – PR Already Merged

Bito scheduled an automatic review for this pull request, but the review was skipped because this PR was merged before the review could be run.
No action is needed if you didn't intend to review it. To get a review, you can type /review in a comment and save it

rusackas added a commit that referenced this pull request Sep 28, 2026
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]>
rusackas added a commit that referenced this pull request Sep 29, 2026
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]>
rusackas added a commit that referenced this pull request Sep 30, 2026
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]>
villebro pushed a commit that referenced this pull request Sep 30, 2026
…3.12 (#44584)

Co-authored-by: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 390bf29)
villebro added a commit that referenced this pull request Sep 30, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

i18n Namespace | Anything related to localization size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants