You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "aminghadersohi (via GitHub)" <gi...@apache.org> on 2026/07/18 09:18:45 UTC
[PR] fix(jinja): handle non-JSON body with JSON content-type in get_form_data [superset]
aminghadersohi opened a new pull request, #42196:
URL: https://github.com/apache/superset/pull/42196
### SUMMARY
`get_form_data()` crashed with an unhandled `werkzeug.exceptions.BadRequest` whenever it ran inside a request context where the `Content-Type` header claimed JSON but the body wasn't actually parseable JSON. This happens for any caller that reaches `get_form_data()` outside a normal chart-data POST — for example the `filter_values()` / `get_filters()` Jinja macros used in chart and dataset SQL templates, when rendered from a request context that isn't a real chart-data request.
`request.is_json` only inspects the `Content-Type` header; it does not guarantee the body is valid, non-empty JSON. `get_form_data()` already has a helper, `loads_request_json()`, that gracefully falls back to `{}` on a JSON parse failure — but that guard was only applied to the `request.form` / `request.args` fallback paths, not to the primary `request.get_json(cache=True)` call, which is the one that was actually raising.
This PR extracts the JSON-body parsing into a small `get_request_json_body()` helper that catches `BadRequest` and falls back to `{}`, matching the existing `loads_request_json()` behavior.
Internal tracking: SC-114072
### TESTING INSTRUCTIONS
- Added `tests/unit_tests/views/test_utils.py::test_get_form_data_handles_non_json_body_with_json_content_type`, which builds a request context with `Content-Type: application/json` and a non-JSON body, and asserts `get_form_data()` returns `({}, None)` instead of raising.
- `pytest tests/unit_tests/views/test_utils.py tests/unit_tests/jinja_context_test.py -q` — 104 passed.
- Manually reproduced the crash against `master` (`request.get_json(cache=True)` raising `BadRequest`) and confirmed the fix resolves it via `app.test_request_context(data="not-json-at-all", content_type="application/json")`.
### 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
--
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(jinja): handle non-JSON body with JSON content-type in get_form_data [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #42196:
URL: https://github.com/apache/superset/pull/42196#issuecomment-5024139774
<!-- Bito Reply -->
The flagged issue is correct. The current implementation of `get_request_json_body()` returns the result of `request.get_json(cache=True)` directly, which can be a non-dict value (e.g., `None`, `int`, `list`), causing `get_form_data()` to crash when it attempts to access it as a mapping. To resolve this, you should ensure the return value is always a dictionary by checking the type of the result from `request.get_json()` and returning `{}` if it is not a mapping.
**superset/views/utils.py**
```
def get_request_json_body() -> dict[Any, Any]:
if not request.is_json:
return {}
try:
data = request.get_json(cache=True)
return data if isinstance(data, dict) else {}
except BadRequest:
return {}
```
--
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(jinja): handle non-JSON body with JSON content-type in get_form_data [superset]
Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on PR #42196:
URL: https://github.com/apache/superset/pull/42196#issuecomment-5041611719
Rebased onto current `master` (resolves the conflict from #42126, which removed `JS_CONTROL_FORM_DATA_KEYS`/`REJECTED_FORM_DATA_KEYS` from the same file/test module) and addressed the [non-dict JSON body finding](https://github.com/apache/superset/pull/42196#discussion_r3627315762) — `get_request_json_body()` now coerces any non-dict JSON body (`null`, scalar, array) to `{}`, with a new regression test. PR is up to date and mergeable.
--
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(jinja): handle non-JSON body with JSON content-type in get_form_data [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #42196:
URL: https://github.com/apache/superset/pull/42196#issuecomment-5042777807
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**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 <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</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(jinja): handle non-JSON body with JSON content-type in get_form_data [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #42196:
URL: https://github.com/apache/superset/pull/42196#issuecomment-5064597386
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**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 <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</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(jinja): handle non-JSON body with JSON content-type in get_form_data [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas merged PR #42196:
URL: https://github.com/apache/superset/pull/42196
--
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(jinja): handle non-JSON body with JSON content-type in get_form_data [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #42196:
URL: https://github.com/apache/superset/pull/42196#issuecomment-5010729015
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
--
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(jinja): handle non-JSON body with JSON content-type in get_form_data [superset]
Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #42196:
URL: https://github.com/apache/superset/pull/42196#discussion_r3615547575
##########
superset/views/utils.py:
##########
@@ -214,6 +215,24 @@ def loads_request_json(request_json_data: str) -> dict[Any, Any]:
return parsed if isinstance(parsed, dict) else {}
+def get_request_json_body() -> dict[Any, Any]:
+ """Parse the request body as JSON, coercing failures to ``{}``.
+
+ ``request.is_json`` only inspects the Content-Type header, not whether the
+ body is actually parseable JSON. Callers reaching ``get_form_data`` from a
+ non-HTTP-chart-data context (e.g. an MCP tool call rendering
+ ``filter_values()``) can have a request context whose Content-Type claims
+ JSON but whose body isn't a JSON chart-data payload, which makes Werkzeug
+ raise ``BadRequest`` from ``request.get_json()``.
+ """
+ if not request.is_json:
+ return {}
+ try:
+ return request.get_json(cache=True)
+ except BadRequest:
+ return {}
Review Comment:
**Suggestion:** `get_request_json_body()` is annotated and used as if it always returns a dict, but `request.get_json(cache=True)` can return valid non-dict JSON values (for example `null`, arrays, or scalars). In those cases `get_form_data()` will later treat the result like a mapping and can raise runtime errors (e.g., membership/get access on `None` or list). Normalize non-dict JSON bodies to `{}` before returning. [logic error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ get_form_data crashes on scalar JSON request bodies.
- ⚠️ Filter_values()/get_filters Jinja macros error under affected requests.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Start the Superset application with the PR code, and note that `get_form_data()` in
`superset/views/utils.py:376-391` now obtains `json_data` via `get_request_json_body()` at
line 383.
2. In a Flask request context (e.g. via `app.test_request_context`), send a request with
`content_type="application/json"` and a valid non-object JSON body such as `"null"` or
`"42"` (scalar JSON). This makes `request.is_json` true and `request.get_json(cache=True)`
return `None` or an int rather than a dict, executed in `get_request_json_body()` at lines
228-232.
3. Within that same request context, call `get_form_data(slice_id=None,
use_slice_data=False, initial_form_data=None)` from `superset/views/utils.py:376-381`.
Execution enters the `has_request_context()` branch and uses the non-dict value returned
from `get_request_json_body()` as `json_data`.
4. When `get_form_data()` evaluates `first_query = (json_data["queries"][0] if "queries"
in json_data and json_data["queries"] else None)` at lines 387-390, the expression
`"queries" in json_data` raises `TypeError` for `None` or scalar values, causing a runtime
crash. This demonstrates that callers treating `json_data` as a mapping will fail when
`get_request_json_body()` returns non-dict JSON.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=f0d82ca5fbb849b3b198d0050d1983de&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=f0d82ca5fbb849b3b198d0050d1983de&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/views/utils.py
**Line:** 218:233
**Comment:**
*Logic Error: `get_request_json_body()` is annotated and used as if it always returns a dict, but `request.get_json(cache=True)` can return valid non-dict JSON values (for example `null`, arrays, or scalars). In those cases `get_form_data()` will later treat the result like a mapping and can raise runtime errors (e.g., membership/get access on `None` or list). Normalize non-dict JSON bodies to `{}` before returning.
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
```
</details>
<a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42196&comment_hash=c2f0401104fe45bc23d50f70fcfc731d9094774f3a92a8fcc724685ac4b99dac&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42196&comment_hash=c2f0401104fe45bc23d50f70fcfc731d9094774f3a92a8fcc724685ac4b99dac&reaction=dislike'>👎</a>
--
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(jinja): handle non-JSON body with JSON content-type in get_form_data [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #42196:
URL: https://github.com/apache/superset/pull/42196#issuecomment-5013324747
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**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 <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</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(jinja): handle non-JSON body with JSON content-type in get_form_data [superset]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #42196:
URL: https://github.com/apache/superset/pull/42196#issuecomment-5010771008
## [Codecov](https://app.codecov.io/gh/apache/superset/pull/42196?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 `77.77778%` with `2 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 64.26%. Comparing base ([`79eff6b`](https://app.codecov.io/gh/apache/superset/commit/79eff6b6f122f04031266d160577a393f23e7f4e?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`e89540c`](https://app.codecov.io/gh/apache/superset/commit/e89540cd2d6cb36e6219915798176496fd4fc8f6?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/42196?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/utils.py](https://app.codecov.io/gh/apache/superset/pull/42196?src=pr&el=tree&filepath=superset%2Fviews%2Futils.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvdmlld3MvdXRpbHMucHk=) | 77.77% | [2 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/42196?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #42196 +/- ##
==========================================
- Coverage 65.08% 64.26% -0.82%
==========================================
Files 2758 2758
Lines 155229 155237 +8
Branches 35572 35573 +1
==========================================
- Hits 101026 99762 -1264
- Misses 52288 53570 +1282
+ Partials 1915 1905 -10
```
| [Flag](https://app.codecov.io/gh/apache/superset/pull/42196/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/42196/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `38.94% <22.22%> (-0.01%)` | :arrow_down: |
| [mysql](https://app.codecov.io/gh/apache/superset/pull/42196/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [postgres](https://app.codecov.io/gh/apache/superset/pull/42196/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/42196/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `40.90% <44.44%> (-0.01%)` | :arrow_down: |
| [python](https://app.codecov.io/gh/apache/superset/pull/42196/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `57.44% <77.77%> (-1.67%)` | :arrow_down: |
| [sqlite](https://app.codecov.io/gh/apache/superset/pull/42196/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `57.30% <77.77%> (+<0.01%)` | :arrow_up: |
| [unit](https://app.codecov.io/gh/apache/superset/pull/42196/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/42196?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(jinja): handle non-JSON body with JSON content-type in get_form_data [superset]
Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on code in PR #42196:
URL: https://github.com/apache/superset/pull/42196#discussion_r3627315762
##########
superset/views/utils.py:
##########
@@ -214,6 +215,24 @@ def loads_request_json(request_json_data: str) -> dict[Any, Any]:
return parsed if isinstance(parsed, dict) else {}
+def get_request_json_body() -> dict[Any, Any]:
+ """Parse the request body as JSON, coercing failures to ``{}``.
+
+ ``request.is_json`` only inspects the Content-Type header, not whether the
+ body is actually parseable JSON. Callers reaching ``get_form_data`` from a
+ non-HTTP-chart-data context (e.g. an MCP tool call rendering
+ ``filter_values()``) can have a request context whose Content-Type claims
+ JSON but whose body isn't a JSON chart-data payload, which makes Werkzeug
+ raise ``BadRequest`` from ``request.get_json()``.
+ """
+ if not request.is_json:
+ return {}
+ try:
+ return request.get_json(cache=True)
+ except BadRequest:
+ return {}
Review Comment:
Confirmed — good catch. `request.get_json(cache=True)` can return a well-formed but non-dict JSON value (`null`, a scalar, or an array), which `get_form_data()` then treats as a mapping. Fixed in the latest push: `get_request_json_body()` now returns `{}` unless the parsed body is actually a `dict`, and I added a regression test (`test_get_form_data_handles_non_dict_json_body`) covering a scalar JSON body. Also rebased onto current `master` to resolve the merge conflict from #42126 removing `JS_CONTROL_FORM_DATA_KEYS`. See commit 7a1083e.
--
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