Skip to content

Commit

Permalink
fix: don't strip SQL comments
Browse files Browse the repository at this point in the history
Following up in the footsteps of #27725 as comments can be used as a way to pass the database engine hints, or for logging purposes.
  • Loading branch information
mistercrunch committed May 7, 2024
1 parent 10c7896 commit 302e0cd
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
5 changes: 2 additions & 3 deletions superset/db_engine_specs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1134,9 +1134,8 @@ def apply_top_to_sql(cls, sql: str, limit: int) -> str:
cte = None
sql_remainder = None
sql = sql.strip(" \t\n;")
sql_statement = sqlparse.format(sql, strip_comments=True)
query_limit: int | None = sql_parse.extract_top_from_query(
sql_statement, cls.top_keywords
sql, cls.top_keywords
)
if not limit:
final_limit = query_limit
Expand All @@ -1145,7 +1144,7 @@ def apply_top_to_sql(cls, sql: str, limit: int) -> str:
else:
final_limit = limit
if not cls.allows_cte_in_subquery:
cte, sql_remainder = sql_parse.get_cte_remainder_query(sql_statement)
cte, sql_remainder = sql_parse.get_cte_remainder_query(sql)
if cte:
str_statement = str(sql_remainder)
cte = cte + "\n"
Expand Down
2 changes: 1 addition & 1 deletion superset/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,7 @@ def get_rendered_sql(
_("Virtual dataset query cannot consist of multiple statements")
)

sql = script.statements[0].format(comments=False)
sql = script.statements[0].format()
if not sql:
raise QueryObjectValidationError(_("Virtual dataset query cannot be empty"))
return sql
Expand Down
1 change: 0 additions & 1 deletion superset/sqllab/query_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def render(self, execution_context: SqlJsonExecutionContext) -> str:

parsed_query = ParsedQuery(
query_model.sql,
strip_comments=True,
engine=query_model.database.db_engine_spec.engine,
)
rendered_query = sql_template_processor.process_template(
Expand Down

0 comments on commit 302e0cd

Please sign in to comment.