You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2026/05/18 15:20:39 UTC
(superset) branch tdd/issue-25839-jinja-sync-columns created (now 6e84a2762d6)
This is an automated email from the ASF dual-hosted git repository.
rusackas pushed a change to branch tdd/issue-25839-jinja-sync-columns
in repository https://gitbox.apache.org/repos/asf/superset.git
at 6e84a2762d6 test(datasets): regression test for Jinja not rendered on sync columns (#25839)
This branch includes the following new commits:
new 6e84a2762d6 test(datasets): regression test for Jinja not rendered on sync columns (#25839)
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(superset) 01/01: test(datasets): regression test for Jinja not rendered on sync columns (#25839)
Posted by ru...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rusackas pushed a commit to branch tdd/issue-25839-jinja-sync-columns
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 6e84a2762d6ca14a038044a042a7746b02b17c7f
Author: Claude Code <no...@anthropic.com>
AuthorDate: Mon May 18 08:19:51 2026 -0700
test(datasets): regression test for Jinja not rendered on sync columns (#25839)
TDD-style validation of #25839: ensures get_virtual_table_metadata calls the
template processor with the raw SQL before passing the result to sqlglot, so
that a virtual dataset containing {{ from_dttm }} or other Jinja tokens
doesn't produce an "Invalid SQL" error when the user clicks SYNC COLUMNS.
Closes #25839
Co-Authored-By: Claude Sonnet 4.6 <no...@anthropic.com>
---
tests/unit_tests/connectors/sqla/utils_test.py | 35 ++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/tests/unit_tests/connectors/sqla/utils_test.py b/tests/unit_tests/connectors/sqla/utils_test.py
index ef17bd9b280..f40934289f1 100644
--- a/tests/unit_tests/connectors/sqla/utils_test.py
+++ b/tests/unit_tests/connectors/sqla/utils_test.py
@@ -137,3 +137,38 @@ def test_get_virtual_table_metadata_multiple(mocker: MockerFixture) -> None:
with pytest.raises(SupersetSecurityException) as excinfo:
get_virtual_table_metadata(dataset)
assert str(excinfo.value) == "Only single queries supported"
+
+
+def test_get_virtual_table_metadata_renders_jinja(mocker: MockerFixture) -> None:
+ """Regression for #25839: Jinja templates in a virtual dataset's SQL must
+ be rendered via the template processor before SQL parsing. Otherwise the
+ raw Jinja tokens reach sqlglot and the parser rejects them as a syntax
+ error (the user-visible symptom is "Invalid SQL" when clicking
+ "SYNC COLUMNS FROM SOURCE" on a dataset that uses {{ from_dttm }} etc.).
+ """
+ mocker.patch(
+ "superset.connectors.sqla.utils.get_columns_description",
+ return_value=[{"name": "rendered_col", "type": "INTEGER"}],
+ )
+
+ raw_sql = "SELECT * FROM tbl WHERE ts > '{{ from_dttm }}'"
+ rendered_sql = "SELECT * FROM tbl WHERE ts > '2024-01-01 00:00:00'"
+
+ dataset = mocker.MagicMock(sql=raw_sql)
+ dataset.database.db_engine_spec.engine = "postgresql"
+ dataset.template_params_dict = {}
+ dataset.get_template_processor().process_template.return_value = rendered_sql
+
+ # If Jinja rendering is skipped, sqlglot tries to parse the raw {{ ... }}
+ # and raises SupersetGenericDBErrorException / SupersetParseError.
+ assert get_virtual_table_metadata(dataset) == [
+ {"name": "rendered_col", "type": "INTEGER"}
+ ]
+
+ # The template processor MUST have been called with the raw SQL (the
+ # whole point of the bug fix). A future regression that re-introduces
+ # the "Jinja not rendered" path would either skip this call or call it
+ # with the wrong input.
+ dataset.get_template_processor().process_template.assert_any_call(
+ raw_sql, **dataset.template_params_dict
+ )