Skip to content

Commit

Permalink
Do not mutate when called from macro
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida committed Mar 14, 2023
1 parent dcdbe48 commit 12fb4d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,12 +876,17 @@ def mutate_query_from_config(self, sql: str) -> str:
def get_template_processor(self, **kwargs: Any) -> BaseTemplateProcessor:
return get_template_processor(table=self, database=self.database, **kwargs)

def get_query_str_extended(self, query_obj: QueryObjectDict) -> QueryStringExtended:
def get_query_str_extended(
self,
query_obj: QueryObjectDict,
mutate: bool = True,
) -> QueryStringExtended:
sqlaq = self.get_sqla_query(**query_obj)
sql = self.database.compile_sqla_query(sqlaq.sqla_query)
sql = self._apply_cte(sql, sqlaq.cte)
sql = sqlparse.format(sql, reindent=True)
sql = self.mutate_query_from_config(sql)
if mutate:
sql = self.mutate_query_from_config(sql)
return QueryStringExtended(
applied_template_filters=sqlaq.applied_template_filters,
applied_filter_columns=sqlaq.applied_filter_columns,
Expand Down
2 changes: 1 addition & 1 deletion superset/jinja_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,6 @@ def dataset_macro(
"metrics": metrics if include_metrics else None,
"columns": columns,
}
sqla_query = dataset.get_query_str_extended(query_obj)
sqla_query = dataset.get_query_str_extended(query_obj, mutate=False)
sql = sqla_query.sql
return f"(\n{sql}\n) AS dataset_{dataset_id}"

0 comments on commit 12fb4d5

Please sign in to comment.