Skip to content

Commit

Permalink
chore: Provide more meaningful SQLGlot error
Browse files Browse the repository at this point in the history
  • Loading branch information
john-bodley committed Apr 2, 2024
1 parent ca47717 commit a2d566e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions superset/sql_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,11 +752,21 @@ def _extract_tables_from_sql(self) -> set[Table]:
statements = parse(self.stripped(), dialect=self._dialect)
except SqlglotError as ex:
logger.warning("Unable to parse SQL (%s): %s", self._dialect, self.sql)
dialect = self._dialect or "generic"

if isinstance(ex, ParseError):
error = ex.errors[0]
suffix = "Check the {dialect}manual for the right syntax to use near '{highlight}' at line {line}".format(
dialect=self._dialect.capitalize() + " " if self._dialect else "",
highlight=error["highlight"],
line=f"{error['line']}:{error['col']}",
)
else:
suffix = ex.args[0]

raise SupersetSecurityException(
SupersetError(
error_type=SupersetErrorType.QUERY_SECURITY_ACCESS_ERROR,
message=__(f"Unable to parse SQL ({dialect}): {self.sql}"),
message=__(f"You have an error in your SQL syntax. {suffix}"),
level=ErrorLevel.ERROR,
)
) from ex
Expand Down

0 comments on commit a2d566e

Please sign in to comment.