You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "Abdulrehman-PIAIC80387 (via GitHub)" <gi...@apache.org> on 2026/08/31 08:12:17 UTC
[PR] fix(mcp): render virtual-dataset Jinja by seeding g.form_data in chart compile + preview (#40570) [superset]
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", "default@example.com") }}'
```
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): render virtual-dataset Jinja by seeding g.form_data in chart compile + preview (#40570) [superset]
Posted by "Abdulrehman-PIAIC80387 (via GitHub)" <gi...@apache.org>.
Abdulrehman-PIAIC80387 closed pull request #43711: fix(mcp): render virtual-dataset Jinja by seeding g.form_data in chart compile + preview (#40570)
URL: https://github.com/apache/superset/pull/43711
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): render virtual-dataset Jinja by seeding g.form_data in chart compile + preview (#40570) [superset]
Posted by "Abdulrehman-PIAIC80387 (via GitHub)" <gi...@apache.org>.
Abdulrehman-PIAIC80387 commented on PR #43711:
URL: https://github.com/apache/superset/pull/43711#issuecomment-5597237317
Closing in favor of #43176, which covers the same two entry points with broader scope (`get_chart_preview`, `get_chart_sql`, `get_table`, `tabular_query`). Consolidating there so review effort isn't split.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): render virtual-dataset Jinja by seeding g.form_data in chart compile + preview (#40570) [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43711:
URL: https://github.com/apache/superset/pull/43711#issuecomment-5491688815
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers an incremental AI Review.
- `/review full` - Manually triggers a full AI Review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): render virtual-dataset Jinja by seeding g.form_data in chart compile + preview (#40570) [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on PR #43711:
URL: https://github.com/apache/superset/pull/43711#issuecomment-5546090346
@aminghadersohi that's.... a lot of details. Is that an "approve"?
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): render virtual-dataset Jinja by seeding g.form_data in chart compile + preview (#40570) [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43711:
URL: https://github.com/apache/superset/pull/43711#issuecomment-5475617120
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): render virtual-dataset Jinja by seeding g.form_data in chart compile + preview (#40570) [superset]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #43711:
URL: https://github.com/apache/superset/pull/43711#issuecomment-5475828914
## [Codecov](https://app.codecov.io/gh/apache/superset/pull/43711?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `0%` with `4 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 66.19%. Comparing base ([`5b64150`](https://app.codecov.io/gh/apache/superset/commit/5b64150d0ac71acdf7299d3a317e8b01e3ab6b61?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`ebb1066`](https://app.codecov.io/gh/apache/superset/commit/ebb1066277a4e53d16225e4a81b4ff35b0635915?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 1 commits behind head on master.
| [Files with missing lines](https://app.codecov.io/gh/apache/superset/pull/43711?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [superset/mcp\_service/chart/compile.py](https://app.codecov.io/gh/apache/superset/pull/43711?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fchart%2Fcompile.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2UvY2hhcnQvY29tcGlsZS5weQ==) | 0.00% | [2 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/43711?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [superset/mcp\_service/chart/preview\_utils.py](https://app.codecov.io/gh/apache/superset/pull/43711?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fchart%2Fpreview_utils.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2UvY2hhcnQvcHJldmlld191dGlscy5weQ==) | 0.00% | [2 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/43711?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #43711 +/- ##
===========================================
- Coverage 79.24% 66.19% -13.06%
===========================================
Files 2888 2888
Lines 166446 166450 +4
Branches 38529 38529
===========================================
- Hits 131907 110176 -21731
- Misses 32046 54037 +21991
+ Partials 2493 2237 -256
```
| [Flag](https://app.codecov.io/gh/apache/superset/pull/43711/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [hive](https://app.codecov.io/gh/apache/superset/pull/43711/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `37.89% <0.00%> (-0.01%)` | :arrow_down: |
| [mysql](https://app.codecov.io/gh/apache/superset/pull/43711/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [postgres](https://app.codecov.io/gh/apache/superset/pull/43711/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [presto](https://app.codecov.io/gh/apache/superset/pull/43711/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `39.80% <0.00%> (-0.01%)` | :arrow_down: |
| [python](https://app.codecov.io/gh/apache/superset/pull/43711/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `57.43% <0.00%> (-26.31%)` | :arrow_down: |
| [sqlite](https://app.codecov.io/gh/apache/superset/pull/43711/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `57.30% <0.00%> (-0.01%)` | :arrow_down: |
| [unit](https://app.codecov.io/gh/apache/superset/pull/43711/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/superset/pull/43711?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): render virtual-dataset Jinja by seeding g.form_data in chart compile + preview (#40570) [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43711:
URL: https://github.com/apache/superset/pull/43711#issuecomment-5478461324
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers an incremental AI Review.
- `/review full` - Manually triggers a full AI Review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): render virtual-dataset Jinja by seeding g.form_data in chart compile + preview (#40570) [superset]
Posted by "Abdulrehman-PIAIC80387 (via GitHub)" <gi...@apache.org>.
Abdulrehman-PIAIC80387 commented on PR #43711:
URL: https://github.com/apache/superset/pull/43711#issuecomment-5489731929
Thanks for the deep review @aminghadersohi — all resolved in `e06be4f`.
- **#1 (ordering):** `side_effect` list now asserts `call_order == ["seed", "run"]`; fails if the seed drifts after `run()`.
- **#2 (inert patch):** Dropped the `has_request_context` patch (compile.py never imports it). New test runs the real `set_query_context_form_data` and asserts `g.form_data` carries the datasource + serialized query — proves the payload is usable, not just that a mock fired.
- **#5 (nit):** Dropped `current_user_email` from both docstrings.
- **#3:** Agreed — coverage floor already held by `test_query_context_form_data_supports_request_dependent_jinja_macros`. Compile-path e2e can be a follow-up.
### Follow-ups / clarifications
- **#4 (`g.form_data` teardown):** Pre-existing across all four peers; a shared teardown feels like its own PR. Happy to file a follow-up issue if you'd like.
- **#6 (conflict with #43572):** Checked #43572 — its files are `chart_utils.py`, `plugins/*`, `schemas.py`, `get_chart_data.py`, `get_chart_type_schema.py`, `test_bubble_chart.py`. Doesn't touch `compile.py` or `preview_utils.py`, so no conflict. Did you mean a different PR?
The identity-resolution note is really useful on the record. Thanks again.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org