eudaimos opened a new issue, #40570:
URL: https://github.com/apache/superset/issues/40570

   ### Bug description
   
   The `superset.mcp_service` `generate_chart` tool (and the chart-preview code 
path it invokes) does not render Jinja in the underlying virtual dataset's SQL. 
Any chart generation against a virtual dataset that depends on a Jinja variable 
fails with `error_type: compile_error`, `details: "Empty query?"`, and 
`error_code: CHART_COMPILE_FAILED`. The chart cannot be saved via MCP.
   
   ### Environment
   
   - Apache Superset image: 
`apachesuperset.docker.scarf.sh/apache/superset:6.1.0rc1`
   - MCP server: `superset.mcp_service` running via `fastmcp` `streamable-http` 
transport (in-process with Flask app), started from the same image as a sidecar 
container.
   - ClickHouse backend (also reproducible on other engines — the SQL is 
rendered unrendered before reaching the engine, so engine choice is incidental).
   - `ENABLE_TEMPLATE_PROCESSING` is enabled (Jinja works fine via the regular 
Explore UI and via SQL Lab).
   
   ### How to reproduce
   
   1. Create a virtual dataset whose SQL references a Jinja variable, e.g.:
      ```sql
      SELECT *
      FROM gold_layer.member_enriched_v1
      WHERE email = '{{ url_param("member_email", "[email protected]") }}'
      ```
      (Also reproducible with bare `{{ member_email }}` plus a dataset-level 
Template Parameters default, and with the Jinja `default` filter.)
   2. Call the MCP `generate_chart` tool against that dataset, e.g.:
      ```json
      {
        "dataset_id": <id>,
        "save_chart": false,
        "config": {
          "chart_type": "table",
          "columns": [{"name": "some_column"}]
        }
      }
      ```
   3. Observe the error response:
      ```json
      {
        "success": false,
        "error": {
          "error_type": "compile_error",
          "message": "Chart query failed to execute. The chart configuration is 
invalid.",
          "details": "Error: Empty query?",
          "error_code": "CHART_COMPILE_FAILED"
        }
      }
      ```
   
   ### Expected behavior
   
   The chart-preview pipeline should render the dataset's Jinja (using 
`url_param` defaults, dataset-level Template Parameters, or both) the same way 
the regular Explore UI does. The preview query should execute and the chart 
should save.
   
   ### Actual behavior
   
   The Jinja templating in the dataset SQL is not invoked at all in the MCP 
chart-generation code path. Confirmed by inspecting `executed_sql` returned 
from `execute_sql` when no `template_params` argument is passed — the Jinja 
literal `{{ ... }}` is sent through to the engine unrendered, despite the 
dataset having Template Parameters configured.
   
   ### Additional observations
   
   - `execute_sql` only renders Jinja when `template_params` is passed 
explicitly as a tool argument. The dataset's saved Template Parameters are not 
consulted by either `execute_sql` or `generate_chart`.
   - Setting `template_params` on the dataset via the dataset edit modal 
persists the value (verified through `list_datasets` `template_params` field), 
but it has no effect on chart generation via MCP.
   - The same dataset works correctly in the Superset UI: opening Explore, 
building a chart, and saving from the UI all render Jinja properly.
   - Workaround: create the chart in the Superset UI. There is no MCP-only 
workaround for this dataset shape.
   
   ### Impact
   
   Any team relying on virtual datasets parameterized with Jinja (a standard 
Superset pattern for high-cardinality lookups, multi-tenant filtering, etc.) 
cannot use MCP to build charts/dashboards against those datasets. In our case 
the underlying table has 400M+ rows, so Jinja-based parameterization is 
required — the MCP is effectively unusable for this dataset.
   
   ### Suggested fix
   
   The MCP chart-preview path should invoke the same `BaseTemplateProcessor` / 
`get_template_processor()` flow that the regular Explore endpoint uses when 
materializing the virtual-dataset SQL, including reading the dataset's 
`template_params` and any `url_param` defaults.


-- 
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]

Reply via email to