mirror of
https://github.com/apache/superset.git
synced 2026-05-21 15:55:10 +00:00
test(datasets): strengthen #25839 guard to verify downstream SQL is rendered
Per @codeant-ai's review: the previous assertion only verified that process_template was called with the raw SQL. A regression that renders Jinja for sqlglot parsing but then passes the original raw SQL to get_columns_description would still produce the user-visible bug while slipping past the test. Now also asserts get_columns_description received the rendered SQL string. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -146,7 +146,7 @@ def test_get_virtual_table_metadata_renders_jinja(mocker: MockerFixture) -> None
|
||||
error (the user-visible symptom is "Invalid SQL" when clicking
|
||||
"SYNC COLUMNS FROM SOURCE" on a dataset that uses {{ from_dttm }} etc.).
|
||||
"""
|
||||
mocker.patch(
|
||||
mock_get_columns_description = mocker.patch(
|
||||
"superset.connectors.sqla.utils.get_columns_description",
|
||||
return_value=[{"name": "rendered_col", "type": "INTEGER"}],
|
||||
)
|
||||
@@ -172,3 +172,16 @@ def test_get_virtual_table_metadata_renders_jinja(mocker: MockerFixture) -> None
|
||||
dataset.get_template_processor().process_template.assert_any_call(
|
||||
raw_sql, **dataset.template_params_dict
|
||||
)
|
||||
|
||||
# End-to-end guard: the rendered SQL must reach get_columns_description,
|
||||
# not the raw Jinja string. A regression where rendering is used for
|
||||
# parsing only and the raw SQL leaks downstream would pass the
|
||||
# process_template assertion above but fail this one.
|
||||
call_args = mock_get_columns_description.call_args
|
||||
assert call_args is not None, "get_columns_description was never called"
|
||||
passed_query = call_args.kwargs.get("query")
|
||||
if passed_query is None and call_args.args:
|
||||
passed_query = call_args.args[-1]
|
||||
assert passed_query == rendered_sql, (
|
||||
f"get_columns_description received unrendered SQL: {passed_query!r}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user