john-bodley commented on code in PR #27858:
URL: https://github.com/apache/superset/pull/27858#discussion_r1548680139


##########
superset/sql_parse.py:
##########
@@ -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(  # pylint: 
disable=consider-using-f-string,line-too-long
+                    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 may have an error in your SQL syntax. 
{suffix}"),

Review Comment:
   I included the work _may_ as `SQLGlot` may result in false positives whilst 
parsing. See [here](https://github.com/tobymao/sqlglot/issues/3247) as an 
example.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to