Repository navigation
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
Open
Raman-Katiyar wants to merge 2 commits into
Raman-Katiyar wants to merge 2 commits into
Conversation
…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.
Contributor
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Marking 'datasource' and 'queries' required on ChartDataQueryContextSchema changes the generated OpenAPI spec; regenerate docs/static/resources/openapi.json so check-openapi-spec-drift passes.
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
SUMMARY
POST /api/v1/chart/datareturned HTTP 500 when the request body was missingdatasourceorqueries:ChartDataQueryContextSchemadid not declare either field required, soschema.load()passed validation and thepost_loadhook calledQueryContextFactory.create()without them, raising a rawTypeError. Marking both fieldsrequired=Truemakes the schema raise aValidationErrorinstead, which the endpoint already maps to HTTP 400.An empty
querieslist 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 otherChartDataQueryContextSchema.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
TypeErrorin the server log. After: HTTP 400 withRequest is incorrect: {'datasource': ['Missing data for required field.'], 'queries': ['Missing data for required field.']}.{"datasource": {"id": 1, "type": "table"}}and with{"queries": []}— both now return 400 naming the missing field.{"columns": ["name"], "metrics": ["count"], "row_limit": 5}) — still HTTP 200 with query results. A request with"queries": []still returns HTTP 200.Automated tests:
tests/unit_tests/charts/data/test_empty_query_context.pycovering 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.pre-commit run: mypy (main), ruff, ruff-format, pylint all passed.ADDITIONAL INFORMATION