This is an automated email from the ASF dual-hosted git repository. sadpandajoe pushed a commit to branch fix-master-unit-tests in repository https://gitbox.apache.org/repos/asf/superset.git
commit 2832e68a3c3d327f28b564660744c71ffd49d48e Author: Joe Li <[email protected]> AuthorDate: Wed Sep 23 14:32:32 2026 -0700 fix(i18n): stop f-strings in gettext leaking a bogus msgid on Python 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]> --- superset/common/query_context_processor.py | 18 ++++++----- superset/translations/messages.pot | 16 +++++++++- .../common/test_query_context_processor.py | 35 ++++++++++++++++++++++ 3 files changed, 61 insertions(+), 8 deletions(-) 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." + )
