richardfogaca opened a new pull request, #40077:
URL: https://github.com/apache/superset/pull/40077
### SUMMARY
`update_chart_preview` already accepted `generate_preview` and
`preview_formats`, but after producing the updated explore URL it always
returned an empty `previews` object. That meant callers could get a table
preview from `generate_chart` and then lose the same requested preview when
updating the generated chart preview.
This change routes supported update-preview formats through the existing
unsaved form-data preview generator after the updated form data has been
mapped, access-checked, validated, and cached. URL previews remain represented
by the returned explore URL fields, so URL-only requests still succeed with
empty data previews.
The change is limited to the MCP update-preview response path and does not
alter saved chart persistence or `generate_chart` preview behavior.
Reviewer focus:
- `superset/mcp_service/chart/tool/update_chart_preview.py` now generates
only supported data preview formats: `ascii`, `table`, and `vega_lite`.
- `tests/unit_tests/mcp_service/chart/tool/test_update_chart_preview.py`
covers the requested table preview path and confirms URL is skipped as a
data-preview format.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A - backend-only MCP chart tool response behavior.
Before this change, an update preview request with `generate_preview: true`
and `preview_formats: ["table"]` returned `previews: {}` even though the
initial chart generation returned a table preview for the same dataset/config
shape.
After this change, the update preview response returns the requested table
preview. Adjacent checks also verified that `ascii`, `table`, and `vega_lite`
are returned when requested, while URL-only requests continue to return the
explore URL with no data preview entries.
### TESTING INSTRUCTIONS
- [x] `docker compose -p superset-sc-104343-update-chart-preview-previews
exec -T superset pytest
tests/unit_tests/mcp_service/chart/tool/test_update_chart_preview.py`
- [x] `docker compose -p superset-sc-104343-update-chart-preview-previews
exec -T superset python -m ruff check
superset/mcp_service/chart/tool/update_chart_preview.py
tests/unit_tests/mcp_service/chart/tool/test_update_chart_preview.py`
- [x] Manual MCP/API verification: call `generate_chart` with
`generate_preview: true` and `preview_formats: ["table"]`, then call
`update_chart_preview` with the returned `form_data_key` and the same preview
parameters. Both responses include a table preview.
- [x] Manual MCP/API regression check: `update_chart_preview` returns
`ascii`, `table`, and `vega_lite` preview keys when all three are requested,
and URL-only preview requests still return success with an explore URL and an
empty `previews` object.
### 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
<!-- agor:pr-summary:begin -->
### What Changed
The update preview API flow now builds data previews after the updated form
data has passed dataset access checks, form-data validation, and explore URL
cache generation. It reuses the existing unsaved form-data preview generator
for supported data-preview formats instead of adding a separate formatter in
the update path.
Only `ascii`, `table`, and `vega_lite` are passed into data-preview
generation. URL and screenshot-style preview requests continue to be
represented by the returned explore URL fields, so URL-only update requests
still return an empty `previews` object.
### Validation
The original bug shape was verified by generating a chart with
`generate_preview: true` and `preview_formats: ["table"]`, then updating it
with the returned `form_data_key` and the same preview options. After the fix,
both responses include a table preview.
Adjacent preview formats were checked by requesting `ascii`, `table`, and
`vega_lite` together from `update_chart_preview`, and URL-only preview requests
still succeed with an explore URL and no data-preview entries. The focused unit
test file for `update_chart_preview` passes with `22 passed`.
### Reviewer Focus
The main behavior contract is in
`superset/mcp_service/chart/tool/update_chart_preview.py`: preview generation
happens only after the updated unsaved chart state is validated and cached. The
corresponding tests in
`tests/unit_tests/mcp_service/chart/tool/test_update_chart_preview.py` cover
the supported table preview path and the URL-skip behavior.
### Risk / Rollback
Risk is limited to the MCP update-preview response path. The change does not
alter saved chart persistence, `generate_chart` preview behavior, or explore
URL generation. Rollback is reverting this PR.
<!-- agor:pr-summary:end -->
--
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]