Abdulrehman-PIAIC80387 opened a new pull request, #43711: URL: https://github.com/apache/superset/pull/43711
### SUMMARY Fixes #40570 (and likely #40732 — see below). The MCP `generate_chart` / `update_chart` / preview tools failed with `CHART_COMPILE_FAILED / Error: Empty query?` for any virtual dataset whose SQL contained Jinja templating. The same dataset worked from Explore. **Root cause (caller-side, not model-side).** The HTTP chart-data endpoint at [`superset/charts/data/api.py:218`](https://github.com/apache/superset/blob/master/superset/charts/data/api.py#L218) calls `set_form_data(json_body)` before `ChartDataCommand.run()` so the Jinja macros that back a virtual dataset's SQL (`url_param`, `filter_values`, `get_filters`, `current_user_email`, …) can resolve their fields via the no-request-context fallback in [`get_form_data()`](https://github.com/apache/superset/blob/master/superset/views/utils.py#L341). Two MCP tools already do the equivalent via `set_query_context_form_data`: - [`get_chart_data`](https://github.com/apache/superset/blob/master/superset/mcp_service/chart/tool/get_chart_data.py#L676) - [`query_dataset`](https://github.com/apache/superset/blob/master/superset/mcp_service/dataset/tool/query_dataset.py#L314) But the chart compile/preview paths had missed it, so the Jinja stayed unrendered and `get_query_str_extended` raised `"Empty query?"` from [`superset/models/helpers.py:4377`](https://github.com/apache/superset/blob/master/superset/models/helpers.py#L4377) as a misleading downstream symptom. **The fix.** One `set_query_context_form_data(query_context, dataset_id, "table")` call inside each of the two entry points: - [`_compile_chart`](https://github.com/apache/superset/blob/master/superset/mcp_service/chart/compile.py) — used by `generate_chart` and `update_chart` via `validate_and_compile` - [`generate_preview_from_form_data`](https://github.com/apache/superset/blob/master/superset/mcp_service/chart/preview_utils.py) — used by chart-preview tools Every chart-generation entry point routes through one of the two, so this covers all three tools without touching `generate_chart.py` or `update_chart.py` directly. The datasource-model side (`get_sqla_query`, `get_query_str_extended`) is unchanged — per @rusackas's [read on the issue](https://github.com/apache/superset/issues/40570#issuecomment-3159049001), that layer already handles `template_params_dict` correctly for any caller. Alignment with the discussion: - @rusackas ([2026-08-07](https://github.com/apache/superset/issues/40570#issuecomment-3159049001)) — model side is fine; fix belongs upstream in the caller ✓ - @sadpandajoe ([2026-06-05](https://github.com/apache/superset/issues/40570#issuecomment-2939858195)) — invited a PR from the reporter ✓ - @eudaimos also flagged #40732 (raw-mode table charts on physical datasets) as a related failure surface; this fix plausibly closes it too but that's for a maintainer to confirm. ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF N/A — server-side fix, no visible UI change. ### TESTING INSTRUCTIONS **Unit tests (added in this PR):** - `tests/unit_tests/mcp_service/chart/test_compile.py::test_compile_chart_seeds_g_form_data_for_jinja_macros` - `tests/unit_tests/mcp_service/chart/test_compile.py::test_compile_chart_seeds_g_form_data_without_request_context` — pins the streamable-http branch (`has_request_context() == False`), which is what the reporter's transport hits (see the note in `tests/unit_tests/mcp_service/test_auth_api_key.py`) - `tests/unit_tests/mcp_service/chart/test_preview_utils.py::test_generate_preview_seeds_g_form_data_for_jinja_macros` Run: ```bash pytest tests/unit_tests/mcp_service/chart/test_compile.py \ tests/unit_tests/mcp_service/chart/test_preview_utils.py -v ``` **End-to-end (for maintainers with a local Superset + MCP stack):** 1. Create a virtual dataset with Jinja in the SQL, e.g. ```sql SELECT * FROM your_table WHERE email = '{{ url_param("member_email", "[email protected]") }}' ``` 2. Call the MCP `generate_chart` tool against it (`save_chart=false`, table config with a single column). 3. Before this PR: `CHART_COMPILE_FAILED / Error: Empty query?`. After: chart compiles and returns data. I don't have a Docker stack handy for a runtime traceback, so the evidence in the diff is the code trace + parity with the two MCP tools that already have the call. Happy to add a traceback in a follow-up comment if useful. ### ADDITIONAL INFORMATION - [x] Has associated issue: #40570 (and plausibly #40732) - [ ] Required feature flags: - [ ] Changes UI - [ ] Includes DB Migration - [ ] Introduces new feature or API - [ ] Removes existing feature or API CC @rusackas @sadpandajoe @aminghadersohi — all engaged on the issue. -- 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]
