You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "eschutho (via GitHub)" <gi...@apache.org> on 2026/10/22 16:35:08 UTC
[PR] fix(api): return 400 instead of 500 for malformed query_context in legacy /api/v1/query/ [superset]
eschutho opened a new pull request, #45636:
URL: https://github.com/apache/superset/pull/45636
### SUMMARY
**Problem.** `POST /api/v1/query/` (legacy `Api.query()`) does `QueryContextFactory.create(**json.loads(request.form["query_context"]))` with no input validation. A malformed JSON value raises a raw `JSONDecodeError`, and valid non-object JSON (`[1,2]`, `5`) raises `TypeError` from `**`. `handle_api_exception`'s broad `except Exception` logs both at ERROR and returns HTTP 500, although both are user-fixable input errors.
**Fix.** Parse the form field in a `try/except ValueError` and raise `QueryObjectValidationError` (status 400) with a clear message; also raise it when the parsed value is not a JSON object. Only this endpoint is touched. A missing `query_context` key still yields `BadRequestKeyError` (already 400) and is unchanged.
This is the same bug class as #42366 / #42401 (sibling-drift): the `time_range` endpoint in the same file already catches `ValueError` and returns a 4xx, while `query()` did not.
**Tradeoffs.** Status changes from 500 to 400 for bad input, and a non-dict value is now a 400 rather than a `TypeError`-induced 500. Clients that (unlikely) keyed off the 500 for malformed input will see a 400.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A (API-only change).
### TESTING INSTRUCTIONS
```
pytest tests/unit_tests/views/test_api_query.py
```
New parametrized tests POST `{not json`, `[1, 2]`, `5`, `"a string"` and `null` as `query_context` and assert 400 with the message present and the factory not called; a sanity test confirms a valid JSON object still reaches `QueryContextFactory.create`. The invalid-input tests fail (500) on `master` and pass with this change.
Manually: `curl -X POST -d 'query_context={not json' <superset>/api/v1/query/` (authenticated) now returns 400 instead of 500.
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] 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](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(api): return 400 instead of 500 for malformed query_context in legacy /api/v1/query/ [superset]
Posted by "eschutho (via GitHub) via notifications" <no...@superset.apache.org>.
eschutho merged PR #45636:
URL: https://github.com/apache/superset/pull/45636
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(api): return 400 instead of 500 for malformed query_context in legacy /api/v1/query/ [superset]
Posted by "netlify[bot] (via GitHub)" <gi...@apache.org>.
netlify[bot] commented on PR #45636:
URL: https://github.com/apache/superset/pull/45636#issuecomment-6352376142
### <span aria-hidden="true">✅</span> Deploy Preview for *superset-docs-preview* ready!
| Name | Link |
|:-:|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | d296abff2fffb24aa938d40bebdf818abdfff42b |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/projects/superset-docs-preview/deploys/6ada8874c1b8e1669628a941 |
|<span aria-hidden="true">😎</span> Deploy Preview | [https://deploy-preview-45636--superset-docs-preview.netlify.app](https://deploy-preview-45636--superset-docs-preview.netlify.app) |
|<span aria-hidden="true">📱</span> Preview on mobile | <details><summary> Toggle QR Code... </summary><br /><br /><br /><br />_Use your smartphone camera to open QR code link._</details> |
|<span aria-hidden="true">🤖</span> Make changes | [Run an agent on this branch](https://app.netlify.com/projects/superset-docs-preview/agent-runs#DcpLCoAgEADQu8y6AQ0x7QYdY_yVYGlSkER3z91bvBdKzXu5YAYYwFQ67NYd4oPJr2QbnrevDalENOQw5LqjYKxn50vKbXG9S3Kk1CQsN8pzKbUcFWnB4fsB) |
---
<!-- [superset-docs-preview Preview](https://deploy-preview-45636--superset-docs-preview.netlify.app) -->
_To edit notification comments on pull requests, go to your [Netlify project configuration](https://app.netlify.com/projects/superset-docs-preview/configuration/notifications#deploy-notifications)._
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(api): return 400 instead of 500 for malformed query_context in legacy /api/v1/query/ [superset]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #45636:
URL: https://github.com/apache/superset/pull/45636#issuecomment-6346545904
## [Codecov](https://app.codecov.io/gh/apache/superset/pull/45636?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `50.00000%` with `4 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 65.37%. Comparing base ([`dfd84bf`](https://app.codecov.io/gh/apache/superset/commit/dfd84bf3d9ebcf64dd479e94ce43a39ed7597206?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`32e5745`](https://app.codecov.io/gh/apache/superset/commit/32e574555325766d590b8ff544c707fe34d78f8a?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 2 commits behind head on master.
| [Files with missing lines](https://app.codecov.io/gh/apache/superset/pull/45636?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [superset/views/api.py](https://app.codecov.io/gh/apache/superset/pull/45636?src=pr&el=tree&filepath=superset%2Fviews%2Fapi.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvdmlld3MvYXBpLnB5) | 50.00% | [3 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/superset/pull/45636?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
> :exclamation: There is a different number of reports uploaded between BASE (dfd84bf) and HEAD (32e5745). Click for more details.
>
> <details><summary>HEAD has 4 uploads less than BASE</summary>
>
>| Flag | BASE (dfd84bf) | HEAD (32e5745) |
>|------|------|------|
>|python|7|3|
></details>
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #45636 +/- ##
===========================================
- Coverage 84.11% 65.37% -18.74%
===========================================
Files 3056 3056
Lines 201360 201367 +7
Branches 47083 47084 +1
===========================================
- Hits 169365 131639 -37726
- Misses 28750 66761 +38011
+ Partials 3245 2967 -278
```
| [Flag](https://app.codecov.io/gh/apache/superset/pull/45636/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [hive](https://app.codecov.io/gh/apache/superset/pull/45636/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `34.88% <12.50%> (-0.01%)` | :arrow_down: |
| [mysql](https://app.codecov.io/gh/apache/superset/pull/45636/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `52.83% <50.00%> (-0.01%)` | :arrow_down: |
| [postgres](https://app.codecov.io/gh/apache/superset/pull/45636/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [presto](https://app.codecov.io/gh/apache/superset/pull/45636/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `36.61% <12.50%> (-0.01%)` | :arrow_down: |
| [python](https://app.codecov.io/gh/apache/superset/pull/45636/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `52.91% <50.00%> (-34.45%)` | :arrow_down: |
| [sqlite](https://app.codecov.io/gh/apache/superset/pull/45636/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [unit](https://app.codecov.io/gh/apache/superset/pull/45636/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/superset/pull/45636?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(api): return 400 instead of 500 for malformed query_context in legacy /api/v1/query/ [superset]
Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on PR #45636:
URL: https://github.com/apache/superset/pull/45636#issuecomment-6346067822
## CodeAnt PR Risk: Low Risk
- The PR appears safe to merge; no actionable issues were identified in the review.
**Assessed commit:** `32e574555325`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org