Skip to content

fix(explore): show validation errors in View Query modal#35969

Merged
sadpandajoe merged 6 commits into
masterfrom
issue-35492-fix-show-query-with-error
Nov 10, 2025
Merged

fix(explore): show validation errors in View Query modal#35969
sadpandajoe merged 6 commits into
masterfrom
issue-35492-fix-show-query-with-error

Conversation

@sadpandajoe
Copy link
Copy Markdown
Member

@sadpandajoe sadpandajoe commented Nov 4, 2025

SUMMARY

Fixes #35492 - Restores the ability to view helpful information in the "View Query" modal when chart queries fail.

This PR addresses a regression introduced during the 2023 command reorganization (commit 07bcfa9) that broke error handling for the View Query feature. Previously in Superset 4.1.3, when charts failed, users could view either SQL or error messages. The reorganization caused all errors to return 400 status codes, making the frontend unable to display any helpful information.

Two types of errors are now properly handled:

  1. Validation errors (Phase 1): Occur before SQL generation (e.g., missing required fields, invalid metrics)
    - Before: Blank modal or generic "Sorry, An error occurred" message
    - After: Clear error message displayed in Alert component
  2. Parsing errors (Phase 2): Occur after SQL generation during optimization (e.g., SQL syntax issues)
    - Before: 500 error, SQL lost completely
    - After: Both error message AND SQL displayed together

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

After
Screenshot 2025-11-05 at 4 46 10 PM

Screenshot 2025-11-06 at 7 58 29 PM

TESTING INSTRUCTIONS

Automated Tests

# Backend unit tests
pytest tests/unit_tests/charts/commands/data/test_get_data_command.py -v

# Frontend component test
npm run test -- ViewQueryModal.test.tsx

Manual Testing

Test Case 1: Validation Error (The Fix)

  1. Create a chart in Explore view
  2. Add duplicate metric labels (e.g., add "sum__num" twice)
  3. Click "View Query" button
  4. Expected: Red Alert shows "Duplicate column/metric labels: sum__num"
  5. Before fix: Blank panel or generic error

Test Case 2: Valid Chart (No Regression)

  1. Create a valid chart
  2. Click "View Query"
  3. Expected: SQL query displayed normally
  4. Verify: No regression on happy path

Test Case 3: Database Error (No Regression)

  1. Create a chart with invalid column in database
  2. Click "View Query"
  3. Expected: Shows SQL query (generated before execution error)
  4. Verify: Database errors still work

ADDITIONAL INFORMATION

@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented Nov 4, 2025

Code Review Agent Run #a4a403

Actionable Suggestions - 0
Additional Suggestions - 5
  • tests/unit_tests/charts/commands/data/test_get_data_command.py - 3
    • Missing module docstring in test file · Line 1-1
      Add a module-level docstring to describe the purpose of this test file. This helps with code documentation and maintainability.
      Code suggestion
       @@ -17,6 +17,10 @@
      -# under the License.
      -
      -from unittest.mock import Mock
      +# under the License.
      +"""
      +Unit tests for ChartDataCommand functionality.
      +"""
      +
      +from unittest.mock import Mock
    • Docstring formatting needs blank line separation · Line 29-29
      Add a blank line between the summary line and description in the docstring. This issue also appears in functions at lines 61, 84, 106, 129, 152, and 188.
      Code suggestion
       @@ -28,7 +28,8 @@
      -def test_query_result_type_allows_validation_error_payload() -> None:
      -    """
      -    Regression test: Ensure result_type='query' with error payload returns
      -    the error instead of raising ChartDataQueryFailedError.
      +def test_query_result_type_allows_validation_error_payload() -> None:
      +    """Regression test: Ensure result_type='query' with error payload returns the error.
      +
      +    Instead of raising ChartDataQueryFailedError, validation errors should pass through.
    • Missing trailing comma in dictionary literal · Line 46-46
      Add trailing comma after the dictionary entry. This issue also appears at lines 71, 93, 115, 138, 166, and 200.
      Code suggestion
       @@ -45,7 +45,7 @@
      -    mock_query_context.get_payload.return_value = {
      -        "queries": [{"error": "Missing temporal column", "language": "sql"}]
      -    }
      +    mock_query_context.get_payload.return_value = {
      +        "queries": [{"error": "Missing temporal column", "language": "sql"}],
      +    }
  • tests/unit_tests/charts/commands/data/__init__.py - 1
    • Missing docstring in public package · Line 1-1
      The `__init__.py` file is missing a docstring. Consider adding a module-level docstring to document the package's purpose and contents.
      Code suggestion
       @@ -16,0 +17,3 @@
        # under the License.
      +"""
      +Unit tests for chart data commands.
      +"""
  • superset/charts/schemas.py - 1
    • Missing trailing comma in tuple · Line 1487-1487
      Missing trailing comma after `allow_none=None` on line 1487. This violates the COM812 rule and should be fixed for consistency with the codebase style.
      Code suggestion
       @@ -1479,9 +1479,9 @@
      -    is_cached = fields.Boolean(
      -        metadata={"description": "Is the result cached"},
      -        required=True,
      -        allow_none=None,
      -    )
      +    is_cached = fields.Boolean(
      +        metadata={"description": "Is the result cached"},
      +        required=True,
      +        allow_none=None,
      +    )
Review Details
  • Files reviewed - 6 · Commit Range: f04b81e..bf4a66e
    • superset-frontend/src/explore/components/controls/ViewQueryModal.test.tsx
    • superset-frontend/src/explore/components/controls/ViewQueryModal.tsx
    • superset/charts/schemas.py
    • superset/commands/chart/data/get_data_command.py
    • tests/unit_tests/charts/commands/data/__init__.py
    • tests/unit_tests/charts/commands/data/test_get_data_command.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Default Agent You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@dosubot dosubot Bot added the explore Namespace | Anything related to Explore label Nov 4, 2025
Copy link
Copy Markdown

@korbit-ai korbit-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Status
Functionality Negative logic in result type check may bypass error handling ▹ view
Functionality Potential undefined language prop ▹ view
Functionality Missing validation for query field on successful status ▹ view
Files scanned
File Path Reviewed
superset/commands/chart/data/get_data_command.py
superset-frontend/src/explore/components/controls/ViewQueryModal.tsx
superset/charts/schemas.py

Explore our documentation to understand the languages and file types we support and the files we ignore.

Check out our docs on how you can make Korbit work best for you and your team.

Loving Korbit!? Share us on LinkedIn Reddit and X

Comment thread superset/commands/chart/data/get_data_command.py
Comment thread superset-frontend/src/explore/components/controls/ViewQueryModal.tsx Outdated
Comment thread superset/charts/schemas.py
@sadpandajoe sadpandajoe added the 🎪 ⚡ showtime-trigger-start Create new ephemeral environment for this PR label Nov 4, 2025
@github-actions github-actions Bot added 🎪 bf4a66e 🚦 building and removed 🎪 ⚡ showtime-trigger-start Create new ephemeral environment for this PR labels Nov 4, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 4, 2025

🎪 Showtime is building environment on GHA for bf4a66e

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 4, 2025

🎪 Showtime deployed environment on GHA for bf4a66e

Environment: http://35.92.249.128:8080 (admin/admin)
Lifetime: 48h auto-cleanup
Updates: New commits create fresh environments automatically

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 6, 2025

🎪 Showtime is building environment on GHA for 345a93e

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 7, 2025

🎪 Showtime deployed environment on GHA for 565fcfb

Environment: http://18.236.166.70:8080 (admin/admin)
Lifetime: 48h auto-cleanup
Updates: New commits create fresh environments automatically

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 7, 2025

🎪 Showtime is building environment on GHA for 2f41fce

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 7, 2025

🎪 Showtime deployed environment on GHA for 2f41fce

Environment: http://52.40.60.56:8080 (admin/admin)
Lifetime: 48h auto-cleanup
Updates: New commits create fresh environments automatically

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 7, 2025

🎪 Showtime is building environment on GHA for 3f34a81

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 7, 2025

🎪 Showtime deployed environment on GHA for 3f34a81

Environment: http://44.244.205.125:8080 (admin/admin)
Lifetime: 48h auto-cleanup
Updates: New commits create fresh environments automatically

sadpandajoe and others added 5 commits November 7, 2025 09:16
When chart queries fail due to validation errors (e.g., missing required fields,
invalid metrics), the View Query modal now displays helpful error messages instead
of showing a blank panel.

This restores functionality that was broken in 2023 when ChartDataCommand was added.
The command raised exceptions for ALL errors, but should only fail-fast for data
execution requests, not query-only requests.

Changes:
- Backend: Skip error check in ChartDataCommand for result_type='query'
- Schema: Make query field optional (validation errors return error without SQL)
- Frontend: Display Alert component for errors, use item.language from backend
- Tests: Add 7 unit tests including regression test to prevent future breakage

Fixes #35492

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add React Testing Library test to verify that ViewQueryModal correctly
displays validation errors in an Alert component when the backend returns
errors in the query result.

This test ensures the fix for issue #35492 continues to work correctly
by verifying the frontend properly renders error messages instead of
showing a blank panel.

Test coverage:
- Mocks chart/data API to return validation error
- Verifies Alert component is rendered
- Verifies error message is displayed

Related to #35492

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…odal

When SQL generation succeeds but optimization/parsing fails, View Query
modal now displays both the error message and the SQL that failed to parse.

This is Phase 2 of the fix for #35492. Phase 1 fixed validation errors
(before SQL generation). Phase 2 fixes parsing errors (after SQL generation,
during optimization).

Backend changes:
- Added SupersetParseError handling in _get_query()
- Extracts SQL from error.extra['sql'] when parsing fails
- Returns both query and error to frontend

Frontend changes:
- Updated ViewQueryModal to render both Alert and ViewQuery simultaneously
- Changed from ternary (either/or) to conditional rendering (both)
- Added Fragment wrapper to support multiple children

Tests:
- Added backend unit test for SupersetParseError handling
- Added frontend test for rendering both error and SQL
- All 8 backend tests passing
- All 2 frontend tests passing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…ery modal

Addresses PR feedback for safer SQL extraction from parsing errors:
- Use explicit None check instead of truthiness to preserve falsy SQL like ""
- Split edge case tests into separate functions for better granularity
- Remove time-specific references from test docstrings

Changes:
- query_actions.py: Check `is not None` to avoid discarding valid empty SQL
- test_get_data_command.py: Split combined test into two independent tests
  - test_get_query_handles_parsing_error_with_missing_sql_key
  - test_get_query_handles_parsing_error_with_null_sql_value

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Addresses PR feedback:
- Remove redundant keys from Alert and ViewQuery components (Fragment already has key)
- Improve Fragment key to use content-based identifiers (query/error content) instead of array index

This follows React best practices by:
1. Avoiding duplicate keys on conditionally rendered children
2. Using stable, content-based keys instead of index-based keys

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 7, 2025

🎪 Showtime is building environment on GHA for 7620bc8

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment on lines +93 to +96
// Use content-based key when available, fall back to index
const key = item.query || item.error || `result-${index}`;
return (
<Fragment key={key}>
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using query or error text as a React key could cause issues if the same error/query appears multiple times, or if very long SQL queries are used as keys. Consider using a more stable identifier or always use the index-based key pattern.

Suggested change
// Use content-based key when available, fall back to index
const key = item.query || item.error || `result-${index}`;
return (
<Fragment key={key}>
// Use index as key to avoid issues with duplicate or long query/error strings
return (
<Fragment key={index}>

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 7, 2025

🎪 Showtime deployed environment on GHA for 7620bc8

Environment: http://52.24.34.130:8080 (admin/admin)
Lifetime: 48h auto-cleanup
Updates: New commits create fresh environments automatically

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 7, 2025

🎪 Showtime is building environment on GHA for 5030db3

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 7, 2025

🎪 Showtime deployed environment on GHA for 5030db3

Environment: http://35.95.73.104:8080 (admin/admin)
Lifetime: 48h auto-cleanup
Updates: New commits create fresh environments automatically

…ebase patterns

Changed from content-based keys (item.query || item.error) to index-based
keys for the Fragment elements in ViewQueryModal. This aligns with
established Superset patterns (e.g., MarshmallowErrorMessage.tsx) for
displaying static API response data. Both approaches are technically
correct for static data, but index-based is simpler and more consistent.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 7, 2025

🎪 Showtime is building environment on GHA for add009b

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 7, 2025

🎪 Showtime deployed environment on GHA for add009b

Environment: http://35.166.36.14:8080 (admin/admin)
Lifetime: 48h auto-cleanup
Updates: New commits create fresh environments automatically

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

@dosubot dosubot Bot mentioned this pull request Apr 3, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels explore Namespace | Anything related to Explore size/XL v6.0 Label added by the release manager to track PRs to be included in the 6.0 branch 🍒 6.0.0 Cherry-picked to 6.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"View query" on a chart whose query errored shows error message, not query (6.0.0rc2)

3 participants