This is an automated email from the ASF dual-hosted git repository.
rusackas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 390bf299ff9 fix(i18n): stop f-strings in gettext leaking a bogus msgid
on Python 3.12 (#44584)
390bf299ff9 is described below
commit 390bf299ff98c47dfa2909037e9c26897d1557ee
Author: Joe Li <[email protected]>
AuthorDate: Wed Sep 23 15:34:05 2026 -0700
fix(i18n): stop f-strings in gettext leaking a bogus msgid on Python 3.12
(#44584)
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
pyproject.toml | 3 ++
superset/common/query_context_processor.py | 18 ++++++-----
superset/translations/messages.pot | 16 +++++++++-
.../common/test_query_context_processor.py | 35 ++++++++++++++++++++++
4 files changed, 64 insertions(+), 8 deletions(-)
diff --git a/pyproject.toml b/pyproject.toml
index 62ac9a2dd08..3756ebb7d23 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -455,6 +455,9 @@ select = [
"F",
"G",
"I",
+ # f-strings passed to gettext are never translatable, and on Python
+ # 3.12+ babel extracts bogus msgids from their replacement fields.
+ "INT001",
"N",
"PT",
"Q",
diff --git a/superset/common/query_context_processor.py
b/superset/common/query_context_processor.py
index 2c27fb9fb06..eed87377bae 100644
--- a/superset/common/query_context_processor.py
+++ b/superset/common/query_context_processor.py
@@ -885,9 +885,11 @@ class QueryContextProcessor:
if not (chart := ChartDAO.find_by_id(annotation_layer["value"])):
raise QueryObjectValidationError(
_(
- f"""Chart with ID {annotation_layer["value"]} (referenced
by
- annotation layer '{annotation_layer["name"]}') was not
found.
- Please verify that the chart exists and is accessible."""
+ "Chart with ID %(chart_id)s (referenced by annotation
layer "
+ "'%(layer_name)s') was not found. Please verify that the "
+ "chart exists and is accessible.",
+ chart_id=annotation_layer["value"],
+ layer_name=annotation_layer["name"],
)
)
@@ -895,10 +897,12 @@ class QueryContextProcessor:
if not (query_context := chart.get_query_context()):
raise QueryObjectValidationError(
_(
- f"""The query context for chart ID {chart.id}
(referenced
- by annotation layer '{annotation_layer["name"]}') was
not found.
- Please ensure the chart is properly configured and has
a valid
- query context."""
+ "The query context for chart ID %(chart_id)s
(referenced "
+ "by annotation layer '%(layer_name)s') was not found. "
+ "Please ensure the chart is properly configured and
has a "
+ "valid query context.",
+ chart_id=chart.id,
+ layer_name=annotation_layer["name"],
)
)
diff --git a/superset/translations/messages.pot
b/superset/translations/messages.pot
index ce808757bac..af2e9f55038 100644
--- a/superset/translations/messages.pot
+++ b/superset/translations/messages.pot
@@ -25,7 +25,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Superset VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
-"POT-Creation-Date: 2026-09-23 10:56-0300\n"
+"POT-Creation-Date: 2026-09-23 14:29-0700\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -3302,6 +3302,13 @@ msgstr ""
msgid "Chart width"
msgstr ""
+#, python-format
+msgid ""
+"Chart with ID %(chart_id)s (referenced by annotation layer "
+"'%(layer_name)s') was not found. Please verify that the chart exists and "
+"is accessible."
+msgstr ""
+
msgid "Charts"
msgstr ""
@@ -14417,6 +14424,13 @@ msgstr ""
msgid "The query context datasource does not match the chart datasource"
msgstr ""
+#, python-format
+msgid ""
+"The query context for chart ID %(chart_id)s (referenced by annotation "
+"layer '%(layer_name)s') was not found. Please ensure the chart is "
+"properly configured and has a valid query context."
+msgstr ""
+
msgid "The query couldn't be loaded"
msgstr ""
diff --git a/tests/unit_tests/common/test_query_context_processor.py
b/tests/unit_tests/common/test_query_context_processor.py
index 5dc21d12b85..117741bb372 100644
--- a/tests/unit_tests/common/test_query_context_processor.py
+++ b/tests/unit_tests/common/test_query_context_processor.py
@@ -2742,3 +2742,38 @@ def
test_contribution_uses_decimal_totals_rather_than_zero():
contribution_totals={"unrelated_metric": Decimal("40.0")},
)
assert collapsed["%decimal_metric"].tolist() == [0, 0]
+
+
+def test_get_viz_annotation_data_reports_missing_chart(app_context) -> None:
+ with patch(
+ "superset.common.query_context_processor.ChartDAO.find_by_id",
+ return_value=None,
+ ):
+ with pytest.raises(QueryObjectValidationError) as excinfo:
+ QueryContextProcessor.get_viz_annotation_data(
+ {"value": 42, "name": "My layer"}, force=False
+ )
+
+ assert str(excinfo.value.message) == (
+ "Chart with ID 42 (referenced by annotation layer 'My layer') was not "
+ "found. Please verify that the chart exists and is accessible."
+ )
+
+
+def test_get_viz_annotation_data_reports_missing_query_context(app_context) ->
None:
+ chart = MagicMock(id=42)
+ chart.get_query_context.return_value = None
+ with patch(
+ "superset.common.query_context_processor.ChartDAO.find_by_id",
+ return_value=chart,
+ ):
+ with pytest.raises(QueryObjectValidationError) as excinfo:
+ QueryContextProcessor.get_viz_annotation_data(
+ {"value": 42, "name": "My layer"}, force=False
+ )
+
+ assert str(excinfo.value.message) == (
+ "The query context for chart ID 42 (referenced by annotation layer "
+ "'My layer') was not found. Please ensure the chart is properly "
+ "configured and has a valid query context."
+ )