Skip to content

fix(charts): return 400 instead of 500 for chart-data requests missing datasource or queries - #46685

Open
Raman-Katiyar wants to merge 2 commits into
apache:masterfrom
Raman-Katiyar:fix/chart-data-missing-required-fields
Open

Raman-Katiyar wants to merge 2 commits into
apache:masterfrom
Raman-Katiyar:fix/chart-data-missing-required-fields

Conversation

@Raman-Katiyar

Copy link
Copy Markdown
Contributor

SUMMARY

POST /api/v1/chart/data returned HTTP 500 when the request body was missing datasource or queries: ChartDataQueryContextSchema did not declare either field required, so schema.load() passed validation and the post_load hook called QueryContextFactory.create() without them, raising a raw TypeError. Marking both fields required=True makes the schema raise a ValidationError instead, which the endpoint already maps to HTTP 400.

An empty queries list stays accepted — deck.gl multi-layer container charts legitimately issue no query of their own. Only the missing fields are newly rejected. I checked the other ChartDataQueryContextSchema.load() call sites (Excel export, MCP chart tools, native filter cache): they all load complete payloads, so this does not change their behaviour.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Not applicable (API-level change, no UI).

TESTING INSTRUCTIONS

  1. Start Superset locally and log in as an admin.
  2. Send a request with an empty body:
    curl -X POST http://localhost:8088/api/v1/chart/data \
      -H "Authorization: Bearer <token>" \
      -H "Content-Type: application/json" \
      -d '{}'
    Before: HTTP 500 with a TypeError in the server log. After: HTTP 400 with Request is incorrect: {'datasource': ['Missing data for required field.'], 'queries': ['Missing data for required field.']}.
  3. Repeat with {"datasource": {"id": 1, "type": "table"}} and with {"queries": []} — both now return 400 naming the missing field.
  4. Send a valid request (existing dataset, e.g. id 1 with {"columns": ["name"], "metrics": ["count"], "row_limit": 5}) — still HTTP 200 with query results. A request with "queries": [] still returns HTTP 200.

Automated tests:

  • New parametrized regression test in tests/unit_tests/charts/data/test_empty_query_context.py covering all three missing-field shapes: fails (3 failed, TypeError) before the fix, passes (4 passed, including the pre-existing empty-queries test) after.
  • tests/unit_tests/charts/: 914 passed, 2 xfailed.
  • Excel export + datasource query tests: 79 passed. MCP chart-tool tests that load this schema: 436 passed. Native filter cache tests: 17 passed.
  • pre-commit run: mypy (main), ruff, ruff-format, pylint all passed.

ADDITIONAL INFORMATION

…g datasource or queries

POST /api/v1/chart/data with a body missing 'datasource' or 'queries'
crashed with a raw TypeError from QueryContextFactory.create(), which
requires both as keyword-only arguments, surfacing as HTTP 500. Marking
both fields required on ChartDataQueryContextSchema makes schema.load()
raise a ValidationError instead, which the endpoint already maps to
HTTP 400. An empty 'queries' list stays accepted (deck.gl multi-layer
container charts issue no query of their own).

Adds regression tests covering the three missing-field shapes.
@codeant-ai-for-open-source

codeant-ai-for-open-source Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟢  Low Risk

  • The PR appears safe to merge; no actionable issues were identified in the review.

Assessed commit: aff4235740cf

@codecov

codecov Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.42%. Comparing base (7819e82) to head (aff4235).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #46685   +/-   ##
=======================================
  Coverage   86.42%   86.42%           
=======================================
  Files        3183     3183           
  Lines      222605   222605           
  Branches    52996    52996           
=======================================
  Hits       192377   192377           
  Misses      26758    26758           
  Partials     3470     3470           
Flag Coverage Δ
hive 33.63% <100.00%> (ø)
mysql 51.82% <100.00%> (-0.01%) ⬇️
postgres 51.85% <100.00%> (ø)
presto 35.32% <100.00%> (ø)
python 88.81% <100.00%> (ø)
sqlite 51.55% <100.00%> (ø)
unit 84.37% <100.00%> (ø)

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.

Marking 'datasource' and 'queries' required on ChartDataQueryContextSchema
changes the generated OpenAPI spec; regenerate docs/static/resources/openapi.json
so check-openapi-spec-drift passes.
@github-actions github-actions Bot added the doc Namespace | Anything related to documentation label Nov 28, 2026

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

doc Namespace | Anything related to documentation size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

POST /api/v1/chart/data returns 500 instead of 400 when the request body is missing datasource or queries

1 participant