eschutho opened a new pull request, #44804:
URL: https://github.com/apache/superset/pull/44804
### SUMMARY
`build_applied_dashboard_filters` in
`superset/mcp_service/chart/chart_helpers.py` parses `dashboard.json_metadata`
and `dashboard.position_json` via `json.loads()` without guarding against
decode errors or non-dict results. When a dashboard has malformed or
non-dict-shaped `json_metadata` (e.g. from old imports or partial saves),
calling the `get_chart_info` MCP tool with a `dashboard_id` raises an unhandled
`JSONDecodeError` or `AttributeError` instead of returning a structured error
or gracefully degrading.
The sibling field `position_json` already had an `isinstance(position_json,
dict)` guard against wrong-type results, but both fields lacked a guard against
decode errors entirely — and `json_metadata` lacked the `isinstance(..., dict)`
check that `position_json` had.
**Fix**: Extract a `_safe_json_loads_dict()` helper that wraps
`json.loads()` in `except (TypeError, ValueError)` with `logger.warning()` and
returns `None` for non-dict results. This matches the existing in-module
precedent in `_apply_unsaved_state_override()` (same catch shape, same warning
pattern) and the `contextlib.suppress(json.JSONDecodeError)` in
`superset/views/utils.py::get_dashboard_extra_filters` which guards parsing of
the same `dashboard.json_metadata` field.
Related: #44731 (same bug class — unguarded JSON parsing in MCP chart
helpers)
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — backend-only change, no UI impact.
### TESTING INSTRUCTIONS
1. Create a dashboard with malformed `json_metadata` (e.g. set
`json_metadata = 'not valid json {{{'` on a Dashboard row)
2. Call `get_chart_info` MCP tool with that `dashboard_id` and a valid
`chart_id` on the dashboard
3. **Before**: unhandled `JSONDecodeError` propagates as a raw exception
4. **After**: returns an empty `dashboard_filters` list, logs a warning
Run the regression tests:
```bash
pytest tests/unit_tests/mcp_service/chart/test_chart_helpers.py -v -k
"build_applied_dashboard_filters"
```
### 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]