Skip to content

Commit

Permalink
trying to progress
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Jun 3, 2024
1 parent cbf4a8e commit 186e925
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
2 changes: 1 addition & 1 deletion superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,7 @@ def get_from_clause(
if not self.is_virtual:
return self.get_sqla_table(), None

from_sql = self.get_rendered_sql(template_processor)
from_sql = self.get_rendered_sql(template_processor) + "\n"
parsed_query = ParsedQuery(from_sql, engine=self.db_engine_spec.engine)
if not (
parsed_query.is_unknown()
Expand Down
13 changes: 3 additions & 10 deletions superset/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1069,8 +1069,7 @@ def get_rendered_sql(
"""
Render sql with template engine (Jinja).
"""

sql = self.sql
sql = self.sql.strip("\t\r\n; ")
if template_processor:
try:
sql = template_processor.process_template(sql)
Expand All @@ -1082,13 +1081,12 @@ def get_rendered_sql(
)
) from ex

script = SQLScript(sql.strip("\t\r\n; "), engine=self.db_engine_spec.engine)
script = SQLScript(sql, engine=self.db_engine_spec.engine)
if len(script.statements) > 1:
raise QueryObjectValidationError(
_("Virtual dataset query cannot consist of multiple statements")
)

sql = script.statements[0].format()
if not sql:
raise QueryObjectValidationError(_("Virtual dataset query cannot be empty"))
return sql
Expand All @@ -1105,12 +1103,7 @@ def get_from_clause(
CTE, the CTE is returned as the second value in the return tuple.
"""

from_sql = self.get_rendered_sql(template_processor)

# TEST this SOLUTION (?)
# Add a line break in case last line happens to be a comment
# from_sql = from_sql + '\n'

from_sql = self.get_rendered_sql(template_processor) + "\n"
parsed_query = ParsedQuery(from_sql, engine=self.db_engine_spec.engine)
if not (
parsed_query.is_unknown()
Expand Down

0 comments on commit 186e925

Please sign in to comment.