Repository navigation
fix(mcp): expose query context to Jinja macros - #42822
aminghadersohi merged 15 commits into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #42822 +/- ##
==========================================
- Coverage 66.69% 66.63% -0.07%
==========================================
Files 2872 2868 -4
Lines 163452 163012 -440
Branches 37725 37507 -218
==========================================
- Hits 109019 108625 -394
+ Misses 52304 52258 -46
Partials 2129 2129
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
The flagged issue is correct. The To resolve this, you should update Would you like me to implement this fix and check the rest of the PR comments for you? superset/charts/data/form_data.py |
Code Review Agent Run #3a654cActionable Suggestions - 0Additional Suggestions - 3
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Code Review Agent Run #a0d65dActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Code Review Agent Run #492ac7Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
gabotorresruiz
left a comment
There was a problem hiding this comment.
Hey Amin, thanks for this fix, the missing Jinja context for programmatic MCP queries is real and worth closing, and thanks for the quick turnaround on the CI failure. Two blocking points below, both verified by execution on this head: the serializer still does not carry what most of the targeted macros read (only get_time_filter() and the implicit metric() dataset lookup actually change behavior), and the new getattr guard shapes production code around a test mock. Details inline with suggested fixes, plus one non-blocking symmetry question.
…ta' into aminghadersohi/mcp-jinja-form-data
|
Addressed the requested changes in the latest head:
Pre-commit passes on all changed files. Targeted pytest collection remains blocked only in this local workspace by its stale sqlglot installation (missing sqlglot.dialects.singlestore); CI has been triggered for head b1daf8b. |
gabotorresruiz
left a comment
There was a problem hiding this comment.
Thanks Amin, this addressed everything and fast. I re-verified on this head with real objects rather than mocks: after set_query_context_form_data, filter_values(), get_filters(), url_param(), get_time_filter() and the implicit metric() dataset lookup all resolve correctly, and a templated virtual dataset rendered through get_query_str_extended now carries the time range and url_params into the generated SQL. The regression tests building real QueryObjects are exactly the shape that would have caught the original gap, and moving the OAuth fixture fix into the test instead of the helper keeps the production contract honest. Scoping the helper to the two MCP data-execution paths with the sibling callers as a follow-up works for me. LGTM.
…ta' into aminghadersohi/mcp-jinja-form-data
|
Final review-comment audit complete:
Latest update: 8c10f89. Pre-commit passes on all changed files. |
There was a problem hiding this comment.
Code Review Agent Run #af39ad
Actionable Suggestions - 1
-
superset/charts/data/form_data.py - 1
- Incorrect filter exposure level · Line 40-40
Additional Suggestions - 1
-
tests/unit_tests/mcp_service/dataset/tool/test_query_dataset.py - 1
-
C098-12745: Inline import should be module-level · Line 190-190Inline import should be at module-level per project convention. Move `QueryObject` to the existing import block at the top of the file.
-
Review Details
-
Files reviewed - 7 · Commit Range:
ab4a0a0..958365b- superset/charts/data/form_data.py
- superset/mcp_service/chart/tool/get_chart_data.py
- superset/mcp_service/dataset/tool/query_dataset.py
- tests/unit_tests/mcp_service/chart/tool/test_get_chart_data.py
- tests/unit_tests/mcp_service/dataset/tool/test_query_dataset.py
- superset/tasks/async_queries.py
- tests/unit_tests/charts/data/form_data_test.py
-
Files skipped - 0
-
Tools
- MyPy (Static Code Analysis) - ✔︎ Successful
- Astral Ruff (Static Code Analysis) - ✔︎ Successful
- Whispers (Secret Scanner) - ✔︎ Successful
- Detect-secrets (Secret Scanner) - ✔︎ Successful
Bito Usage Guide
Commands
Type the following command in the pull request comment and save the comment.
-
/review- 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 documentation for additional commands.
Configuration
This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].
Documentation & Help
|
Reviewed the remaining unresolved Bito thread. It conflated the direct Jinja template-context filter path with the Flask-global form-data fallback: the latter intentionally consumes the plural Unresolved review threads: 0. Review status: APPROVED. Failed checks: 0. |
SUMMARY
The chart data API makes its query request available through Flask's global form-data fallback because Jinja macros such as
filter_values,get_filters, andurl_paramread query inputs from that context. Programmatically constructed MCP queries skipped that step, so virtual datasets and metrics using those macros could fail despite the equivalent API query succeeding.This extracts the API's form-data assignment into a shared helper and uses it for
get_chart_dataandquery_dataset. MCP query contexts are represented in the same datasource/queries/form-data shape consumed by the existing Jinja lookup path; no synthetic request context or duplicated macro-specific behavior is introduced.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Not applicable; this is a backend-only query execution fix.
TESTING INSTRUCTIONS
pytest -q tests/unit_tests/mcp_service/chart/tool/test_get_chart_data.py tests/unit_tests/mcp_service/dataset/tool/test_query_dataset.py(136 passed)pytest -q tests/unit_tests/mcp_service(3318 passed; one unrelated existing health-check smoke failure because the test environment has no version string configured)uvx pre-commit run --files superset/charts/data/api.py superset/charts/data/form_data.py superset/mcp_service/chart/tool/get_chart_data.py superset/mcp_service/dataset/tool/query_dataset.py tests/unit_tests/mcp_service/chart/tool/test_get_chart_data.py tests/unit_tests/mcp_service/dataset/tool/test_query_dataset.pypre-commit run --all-files(Python checks passed; frontend-only hooks could not complete because frontend dependencies such asglobandpostcss-styled-syntaxare not installed; the formatter also reported pre-existing frontend formatting drift)The regression tests execute
filter_valuesandget_filtersduring an MCPquery_datasetcall and coverurl_paramplus implicit dataset lookup formetric()using chart-shaped query context.ADDITIONAL INFORMATION
Blast radius
This affects only MCP chart and dataset query execution plus the existing chart-data API context assignment. It does not change authorization, RLS, workspace isolation, schemas, migrations, feature flags, or non-MCP query behavior.
Risk & rollback
Risk is limited to the Flask-global form-data payload used while compiling MCP queries. The payload is built from the already validated query context and matches the existing API representation. Rollback is a revert of this commit.
Review guidance
Start with
superset/charts/data/form_data.py, then verify the two MCP call sites populate it immediately beforeChartDataCommandexecution. The tests document the request-dependent macro boundary.Eval evidence
No model or prompt evaluation was run because this change does not modify tool schemas, descriptions, prompts, model routing, or generated responses. The deterministic MCP regression coverage passes 136/136; the full MCP unit suite passes 3318/3319 with the environment-only health-check failure described above.
Cost & latency delta
No model parameters, prompts, or tool payload schemas changed, so token and model-cost delta is zero. The added work serializes the already-built query objects once per affected call; no external request or database query is added.
Prompt / non-determinism
No prompt, model routing, or non-deterministic behavior changed.