Skip to content

fix(chart/data): return 400 for query errors on the async cache lookup - #43081

Open
eschutho wants to merge 2 commits into
masterfrom
fix/chart-data-query-validation-error-500
Open

eschutho wants to merge 2 commits into
masterfrom
fix/chart-data-query-validation-error-500

Conversation

@eschutho

@eschutho eschutho commented Aug 12, 2026 •

Copy link
Copy Markdown
Member

SUMMARY

With GLOBAL_ASYNC_QUERIES enabled, ChartDataRestApi._run_async() first probes the cache with command.execute(force_cached=True), but only caught ChartDataCacheLoadError. Any other query error raised during that lookup escaped to Flask's global error handlers instead of getting the handling the sync path in _get_data_response() applies:

Exception on the async cache lookup Before After
ChartDataQueryFailedError (CommandException, status = 500) 500, {"errors": [...]} 400, {"message": ...}
QueryObjectValidationError (status = 400) 400 via generic handler: {"errors": [...]} for JSON clients, the HTML error page for Accept: text/html 400, {"message": ...}
SemanticLayerQueryRejectedError (status = 400) 400 via generic handler, {"errors": [...]} 400, {"message": ...}

ChartDataQueryFailedError is the case users can actually hit. A cached entry that's missing filter metadata is treated as a cache miss, so the "cache-only" probe runs the query live, and a failing query raised 500. The other two exceptions are caught for parity with the sync path. Guests already received a generic error message before this change and still do.

This PR catches the same exceptions in the cache-lookup block that _get_data_response() catches (ChartDataQueryFailedError, SemanticLayerQueryRejectedError, QueryObjectValidationError). It returns the same sanitized 400 response and doesn't enqueue an async job.

The original change on this PR (adding QueryObjectValidationError to _get_data_response()) has since landed on master via #45110, so after rebasing, this PR only covers the async path plus regression tests for both paths.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A (backend only)

TESTING INSTRUCTIONS

New regression tests:

  • tests/unit_tests/charts/test_chart_data_api.py
    • test_get_data_response_returns_400_for_query_object_validation_error
    • test_run_async_returns_400_when_cache_lookup_rejects_the_query (parametrized over all three exceptions; asserts 400, sanitized message, force_cached=True, no task submitted)
  • tests/integration_tests/charts/data/api_tests.py (module-level tests using physical_query_context, so they run even though the TestPostChartDataApi class is skipped)
    • test_chart_data_query_object_validation_error__400 (sync path, end to end)
    • test_chart_data_async_cache_lookup_query_error__400 (GLOBAL_ASYNC_QUERIES=True, async_mode=True, force=False; parametrized over QueryObjectValidationError and ChartDataQueryFailedError)
pytest tests/unit_tests/charts/test_chart_data_api.py
pytest tests/integration_tests/charts/data/api_tests.py -k "query_object_validation_error or cache_lookup_query_error"

I checked the before/after locally by reverting only superset/charts/data/api.py. The new _run_async unit tests and both async integration cases fail without the fix: ChartDataQueryFailedError returns 500, and QueryObjectValidationError returns the generic errors[] body. With the fix, they pass.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags: GLOBAL_ASYNC_QUERIES (for the async path)
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

🤖 Generated with Claude Code

@dosubot dosubot Bot added the api Related to the REST API label Aug 12, 2026
@bito-code-review

bito-code-review Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #495cdd

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 92c4854..92c4854
    • superset/charts/data/api.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ 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 Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

Comment thread superset/charts/data/api.py Outdated
Comment on lines +649 to +650
except QueryObjectValidationError as exc:
return self.response_400(message=sanitize_error_message(exc.message))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: The new handling only covers _get_data_response, but the GLOBAL_ASYNC_QUERIES path calls command.execute(force_cached=True) directly in _run_async, where only ChartDataCacheLoadError is caught. If execution-time validation in get_payload_result() raises QueryObjectValidationError during the cache lookup, it escapes to Flask and returns HTTP 500 instead of 400. Add equivalent handling to the async cache-hit path before scheduling the background job. [incomplete implementation]

Severity Level: Major ⚠️
- ❌ Async chart requests can return HTTP 500 for invalid queries.
- ⚠️ Clients receive server errors instead of validation feedback.
- ⚠️ GLOBAL_ASYNC_QUERIES cache-hit handling remains inconsistent.

Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/charts/data/api.py
**Line:** 649:650
**Comment:**
	*Incomplete Implementation: The new handling only covers `_get_data_response`, but the `GLOBAL_ASYNC_QUERIES` path calls `command.execute(force_cached=True)` directly in `_run_async`, where only `ChartDataCacheLoadError` is caught. If execution-time validation in `get_payload_result()` raises `QueryObjectValidationError` during the cache lookup, it escapes to Flask and returns HTTP 500 instead of 400. Add equivalent handling to the async cache-hit path before scheduling the background job.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@bito-code-review

Copy link
Copy Markdown
Contributor

The flagged issue is correct. The GLOBAL_ASYNC_QUERIES path in _run_async currently lacks the QueryObjectValidationError handling that was added to _get_data_response. To resolve this, you should wrap the command.execute(force_cached=True) call in a try-except block that catches QueryObjectValidationError and returns a 400 response, similar to the implementation in _get_data_response.

superset/charts/data/api.py

try:
            result = command.execute(force_cached=True)
        except QueryObjectValidationError as exc:
            return self.response_400(message=sanitize_error_message(exc.message))
        except ChartDataCacheLoadError:
            # ... existing logic ...

@codecov

codecov Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.97%. Comparing base (2350348) to head (cfc3bcc).
⚠️ Report is 542 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #43081      +/-   ##
==========================================
- Coverage   84.63%   83.97%   -0.67%     
==========================================
  Files        3069     3050      -19     
  Lines      205446   203375    -2071     
  Branches    48306    47373     -933     
==========================================
- Hits       173879   170774    -3105     
- Misses      28277    29312    +1035     
+ Partials     3290     3289       -1     
Flag Coverage Δ
hive 34.53% <0.00%> (-0.01%) ⬇️
mysql 52.56% <100.00%> (+<0.01%) ⬆️
postgres 52.56% <100.00%> (+<0.01%) ⬆️
presto 36.26% <0.00%> (-0.01%) ⬇️
python 87.73% <100.00%> (+<0.01%) ⬆️
sqlite 52.33% <100.00%> (+<0.01%) ⬆️
unit 82.45% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@eschutho
eschutho force-pushed the fix/chart-data-query-validation-error-500 branch from 92c4854 to 45b643a Compare August 12, 2026 23:40
@netlify

netlify Bot commented Aug 12, 2026

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 45b643a
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a7d047b52b8880008ca93e0
😎 Deploy Preview https://deploy-preview-43081--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@bito-code-review

bito-code-review Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #2cd5cc

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 45b643a..45b643a
    • superset/charts/data/api.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ 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 Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@eschutho
eschutho requested a review from richardfogaca August 15, 2026 00:41

@richardfogaca richardfogaca left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Richard's agent here: I found one blocking gap at 45b643a.

  • With GLOBAL_ASYNC_QUERIES enabled, _run_async() still calls command.execute(force_cached=True) while catching only ChartDataCacheLoadError. QueryObjectValidationError can therefore still reach the generic handler as HTTP 500. Could we add equivalent 400 handling to that cache lookup?

  • Wdyt about adding targeted regression cases for both _get_data_response() and _run_async()? The changed line currently has no patch coverage, and the two test paths listed in the PR description do not exist on this head; the relevant modules are tests/unit_tests/charts/test_chart_data_api.py and tests/integration_tests/charts/data/api_tests.py.

With GLOBAL_ASYNC_QUERIES enabled, `_run_async()` probes the cache with
`command.execute(force_cached=True)` but only caught
`ChartDataCacheLoadError`. Query errors raised during that lookup fell
through to the global error handlers, so `ChartDataQueryFailedError`
returned HTTP 500 and validation errors skipped the error-message
sanitization applied on the sync path.

Handle `ChartDataQueryFailedError`, `SemanticLayerQueryRejectedError`
and `QueryObjectValidationError` on the cache lookup the same way
`_get_data_response()` does: a sanitized 400 response, with no async job
enqueued.

Add unit and integration regression tests covering both the sync
(`_get_data_response`) and async cache-lookup (`_run_async`) paths.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@eschutho
eschutho force-pushed the fix/chart-data-query-validation-error-500 branch from 45b643a to ea38b89 Compare October 16, 2026 05:12
@eschutho eschutho changed the title fix(chart/data): handle QueryObjectValidationError in _get_data_response fix(chart/data): return 400 for query errors on the async cache lookup Oct 16, 2026
@eschutho

Copy link
Copy Markdown
Member Author

@richardfogaca thanks for the review. I rebased onto master and addressed both points in ea38b89:

Async cache-hit path: _run_async() now catches ChartDataQueryFailedError, SemanticLayerQueryRejectedError and QueryObjectValidationError around command.execute(force_cached=True). It returns the same sanitized 400 that _get_data_response() returns, and doesn't enqueue a job.

When I checked before/after against current master, the behavior was a bit different from what we'd both assumed. QueryObjectValidationError has status = 400, so on the async path it already returned 400 via the global SupersetException handler. But the body was the generic errors[] shape and skipped sanitize_error_message. The real 500 on that path was ChartDataQueryFailedError (a CommandException, status = 500). The fix and tests cover both.

Tests: you were right that the test paths in the old description didn't exist. The tests are now:

  • tests/unit_tests/charts/test_chart_data_api.py: _get_data_response with QueryObjectValidationError, and _run_async parametrized over all three exceptions
  • tests/integration_tests/charts/data/api_tests.py: end-to-end sync, plus an async (GLOBAL_ASYNC_QUERIES=True, force=False) case for QueryObjectValidationError and ChartDataQueryFailedError. I wrote these as module-level tests on physical_query_context because the TestPostChartDataApi class is skipped on master and tests added there wouldn't run.

With api.py reverted, the _run_async unit tests and both async integration cases fail. With the fix, they pass.

Rebase note: the original _get_data_response() change landed on master via #45110. After the rebase this PR is just the async path plus tests, so I updated the title and description to match.

@codeant-ai-for-open-source

codeant-ai-for-open-source Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟢  Low Risk

  • The PR appears safe to merge; async cache lookups now return 400 for query errors instead of falling through to background scheduling.
  • Tests cover the affected async error cases and confirm no background job is enqueued.

Assessed commit: cfc3bcc0c080

@github-actions github-actions Bot removed the requires:rebase Requires rebasing on top of current master label Oct 16, 2026
@eschutho

Copy link
Copy Markdown
Member Author

@richardfogaca re-requesting your review — the async cache-lookup fix you flagged on 8/17 is in, both regression tests you asked for are added, and CI is fully green on the current head. Would appreciate a re-review when you have a moment.

@eschutho

Copy link
Copy Markdown
Member Author

Hi @rusackas — @richardfogaca requested changes back in August and hasn't had a chance to revisit despite a follow-up ping. CI is green and the PR is otherwise ready. Would you be able to take a look and review when you get a chance? Happy to address any feedback. Thanks!

@eschutho
eschutho requested a review from rusackas November 21, 2026 04:09

@rusackas rusackas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @eschutho, LGTM!

@richardfogaca I believe both of your points from August are covered now (the async cache lookup and the regression tests), so it'd be great if you could clear the block when you get a sec.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Related to the REST API preset-io size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants