aminghadersohi opened a new pull request, #38392:
URL: https://github.com/apache/superset/pull/38392
### SUMMARY
When generating a chart via MCP, the tool previously returned a chart URL
without verifying
that the underlying query actually executes successfully. This meant users
could receive
links to broken charts that fail to render.
This PR adds a compile check step that runs a lightweight test query
(row_limit=2) via
`QueryContextFactory` + `ChartDataCommand` after chart generation. If the
query fails,
a structured error response is returned instead of a broken chart link.
**Behavior:**
- **Saved charts** (`save_chart=True`): If compile check fails, the chart is
deleted from
the database and an error is returned — no broken charts are left behind
- **Preview-only mode** (`save_chart=False`): If compile check fails, an
error is returned
with details about what went wrong
- **Success path**: Compile warnings (if any) are included in the response
The `_compile_chart()` helper catches `ChartDataQueryFailedError`,
`ChartDataCacheLoadError`,
`CommandException`, `ValueError`, and `KeyError` — returning a
`CompileResult` dataclass
with success status, error message, warnings, and row count.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — backend-only change, no UI modifications.
### TESTING INSTRUCTIONS
1. Run the unit tests:
```bash
pytest tests/unit_tests/mcp_service/chart/tool/test_generate_chart.py -v
```
2. Verify all 14 tests pass (10 existing + 4 new compile check tests)
3. The new `TestCompileChart` class covers:
- Successful compile with row count verification
- Query errors embedded in result payload
- `ChartDataQueryFailedError` exceptions
- `ValueError` from invalid configuration
### 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
- [x] 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: [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]