-
Notifications
You must be signed in to change notification settings - Fork 16.7k
fix(explore): show validation errors in View Query modal #35969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c7c7f7e
fix(explore): show validation errors in View Query modal
sadpandajoe b016781
test(explore): add RTL test for ViewQueryModal error rendering
sadpandajoe 00f32b9
fix(explore): show SQL and error for parsing failures in View Query m…
sadpandajoe 7614093
fix(explore): add defensive null checks for SQL extraction in View Qu…
sadpandajoe 7620bc8
refactor(explore): remove duplicate React keys in ViewQueryModal
sadpandajoe add009b
refactor(explore): simplify React keys in ViewQueryModal to match cod…
sadpandajoe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
superset-frontend/src/explore/components/controls/ViewQueryModal.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import { screen, render, waitFor } from 'spec/helpers/testing-library'; | ||
| import fetchMock from 'fetch-mock'; | ||
| import ViewQueryModal from './ViewQueryModal'; | ||
|
|
||
| const mockFormData = { | ||
| datasource: '1__table', | ||
| viz_type: 'table', | ||
| }; | ||
|
|
||
| const chartDataEndpoint = 'glob:*/api/v1/chart/data*'; | ||
|
|
||
| afterEach(() => { | ||
| jest.resetAllMocks(); | ||
| fetchMock.restore(); | ||
| }); | ||
|
|
||
| test('renders Alert component when query result contains validation error', async () => { | ||
| /** | ||
| * Regression test for issue #35492 - Phase 1 | ||
| * Verifies that validation errors from the backend are displayed in an Alert | ||
| * component instead of showing a blank panel | ||
| */ | ||
| // Mock API response with validation error | ||
| fetchMock.post(chartDataEndpoint, { | ||
| result: [ | ||
| { | ||
| error: 'Missing temporal column', | ||
| language: 'sql', | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| render(<ViewQueryModal latestQueryFormData={mockFormData} />, { | ||
| useRedux: true, | ||
| }); | ||
|
|
||
| // Wait for API call to complete | ||
| await waitFor(() => | ||
| expect(fetchMock.calls(chartDataEndpoint)).toHaveLength(1), | ||
| ); | ||
|
|
||
| // Assert Alert component is rendered with error message | ||
| expect(screen.getByRole('alert')).toBeInTheDocument(); | ||
| expect(screen.getByText('Missing temporal column')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('renders both Alert and SQL query when parsing error occurs', async () => { | ||
| /** | ||
| * Regression test for issue #35492 - Phase 2 | ||
| * Verifies that parsing errors (which occur after SQL generation) display | ||
| * both the error message AND the SQL query that failed to parse. | ||
| * | ||
| * This differs from validation errors (Phase 1) where no SQL was generated. | ||
| * For parsing errors, the SQL was successfully compiled but optimization failed. | ||
| */ | ||
| // Mock API response with parsing error (has both query and error) | ||
| fetchMock.post(chartDataEndpoint, { | ||
| result: [ | ||
| { | ||
| query: 'SELECT SUM ( Open', | ||
| error: "Error parsing near 'Open' at line 1:17", | ||
| language: 'sql', | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| render(<ViewQueryModal latestQueryFormData={mockFormData} />, { | ||
| useRedux: true, | ||
| }); | ||
|
|
||
| // Wait for the error message to appear | ||
| await waitFor(() => | ||
| expect( | ||
| screen.getByText("Error parsing near 'Open' at line 1:17"), | ||
| ).toBeInTheDocument(), | ||
| ); | ||
|
|
||
| // Assert Alert component is rendered with error message | ||
| expect(screen.getByRole('alert')).toBeInTheDocument(); | ||
|
|
||
| // Assert SQL query is also displayed | ||
| // Note: The SQL is rendered inside a syntax-highlighted code block where | ||
| // each keyword is in a separate span element | ||
| await waitFor(() => { | ||
| expect(screen.getByText('SELECT')).toBeInTheDocument(); | ||
| expect(screen.getByText('SUM')).toBeInTheDocument(); | ||
| expect(screen.getByText('Open')).toBeInTheDocument(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.