From 00cd069af2f0f44f0182cddbcc3f157c61caeabe Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" <70410625+michael-s-molina@users.noreply.github.com> Date: Tue, 27 May 2025 16:54:54 -0300 Subject: [PATCH] fix: Missing processor context when rendering Jinja (#33596) (cherry picked from commit ce9759785a840d222f31648c81656b2b380ebb57) --- superset/jinja_context.py | 6 ++++++ superset/sql_parse.py | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/superset/jinja_context.py b/superset/jinja_context.py index 4b02a69a75b..3bd8a9c2ecf 100644 --- a/superset/jinja_context.py +++ b/superset/jinja_context.py @@ -590,6 +590,12 @@ class BaseTemplateProcessor: self._context.update(kwargs) self._context.update(context_addons()) + def get_context(self) -> dict[str, Any]: + """ + Returns the current template context. + """ + return self._context.copy() + def process_template(self, sql: str, **kwargs: Any) -> str: """Processes a sql template diff --git a/superset/sql_parse.py b/superset/sql_parse.py index 8fae4507efa..e82e88ea754 100644 --- a/superset/sql_parse.py +++ b/superset/sql_parse.py @@ -972,12 +972,12 @@ def extract_tables_from_jinja_sql(sql: str, database: Database) -> set[Table]: node.data = "NULL" # re-render template back into a string - rendered_template = Template(template).render() + rendered_sql = Template(template).render(processor.get_context()) return ( tables | ParsedQuery( - sql_statement=processor.process_template(rendered_template), + sql_statement=processor.process_template(rendered_sql), engine=database.db_engine_spec.engine, ).tables )