This is an automated email from the ASF dual-hosted git repository.
justinpark pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 8c94f9c435 fix(sqllab): Invalid SQL Error breaks SQL Lab (#33164)
8c94f9c435 is described below
commit 8c94f9c435f126e3bd30890a61966ee81be0f68f
Author: JUST.in DO IT <[email protected]>
AuthorDate: Fri Apr 18 13:31:54 2025 -0700
fix(sqllab): Invalid SQL Error breaks SQL Lab (#33164)
---
.../ErrorMessage/InvalidSQLErrorMessage.test.tsx | 21 +++++++++++++++++++++
.../ErrorMessage/InvalidSQLErrorMessage.tsx | 12 +++++++-----
superset/sql_parse.py | 1 +
3 files changed, 29 insertions(+), 5 deletions(-)
diff --git
a/superset-frontend/src/components/ErrorMessage/InvalidSQLErrorMessage.test.tsx
b/superset-frontend/src/components/ErrorMessage/InvalidSQLErrorMessage.test.tsx
index 423566aa3a..99973b2d2b 100644
---
a/superset-frontend/src/components/ErrorMessage/InvalidSQLErrorMessage.test.tsx
+++
b/superset-frontend/src/components/ErrorMessage/InvalidSQLErrorMessage.test.tsx
@@ -36,6 +36,21 @@ const defaultProps = {
subtitle: 'Test subtitle',
};
+const missingExtraProps = {
+ ...defaultProps,
+ error: {
+ error_type: ErrorTypeEnum.INVALID_SQL_ERROR,
+ message: 'SQLStatement should have exactly one statement',
+ level: 'error' as ErrorLevel,
+ extra: {
+ sql: null,
+ line: null,
+ column: null,
+ engine: null,
+ },
+ },
+};
+
const renderComponent = (overrides = {}) =>
render(<InvalidSQLErrorMessage {...defaultProps} {...overrides} />);
@@ -60,6 +75,12 @@ describe('InvalidSQLErrorMessage', () => {
unmount();
});
+ it('renders the error message with the empty extra properties', () => {
+ const { getByText } = renderComponent(missingExtraProps);
+ expect(getByText('Unable to parse SQL')).toBeInTheDocument();
+ expect(getByText(missingExtraProps.error.message)).toBeInTheDocument();
+ });
+
it('displays the SQL error line and column indicator', async () => {
const { getByText, container, unmount } = renderComponent();
diff --git
a/superset-frontend/src/components/ErrorMessage/InvalidSQLErrorMessage.tsx
b/superset-frontend/src/components/ErrorMessage/InvalidSQLErrorMessage.tsx
index 21236e92a0..27ca263cfd 100644
--- a/superset-frontend/src/components/ErrorMessage/InvalidSQLErrorMessage.tsx
+++ b/superset-frontend/src/components/ErrorMessage/InvalidSQLErrorMessage.tsx
@@ -36,20 +36,22 @@ function InvalidSQLErrorMessage({
source,
subtitle,
}: ErrorMessageComponentProps<SupersetParseErrorExtra>) {
- const { extra, level } = error;
+ const { extra, level, message } = error;
const { sql, line, column } = extra;
- const lines = sql.split('\n');
+ const lines = sql?.split('\n');
let errorLine;
- if (line !== null) errorLine = lines[line - 1];
- else if (lines.length > 0) {
+ if (line !== null && Number.isInteger(line)) errorLine = lines[line - 1];
+ else if (lines?.length > 0) {
errorLine = lines[0];
}
- const body = errorLine && (
+ const body = errorLine ? (
<>
<pre>{errorLine}</pre>
{column !== null && <pre>{' '.repeat(column - 1)}^</pre>}
</>
+ ) : (
+ message
);
return (
<ErrorAlert
diff --git a/superset/sql_parse.py b/superset/sql_parse.py
index b253ab29d0..2cd8d0ac9d 100644
--- a/superset/sql_parse.py
+++ b/superset/sql_parse.py
@@ -277,6 +277,7 @@ class ParsedQuery:
"You may have an error in your SQL statement.
{message}"
).format(message=ex.error.message),
level=ErrorLevel.ERROR,
+ extra=ex.error.extra,
)
) from ex