fix(mcp): honor and validate chart filters - #43478
Conversation
Code Review Agent Run #b67a05Actionable Suggestions - 0Additional Suggestions - 1
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. |
|
The flagged issue is correct. In tests/unit_tests/mcp_service/chart/tool/test_get_chart_sql.py |
|
Thanks — both flagged issues were accurate, confirmed by reproducing them locally. Fixed in dfedf65. 1. Test asserted the wrong error message (codeant + bito). Confirmed real; the test failed: The malformed-filter regression test was written against the fallback path's message, but a later commit in this branch added the saved-context error branch, which reports the malformed filter directly. Updated the assertion to expect 2.
Returning 3. Test gap on the invalid-
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #43478 +/- ##
==========================================
+ Coverage 78.93% 78.96% +0.03%
==========================================
Files 2877 2877
Lines 165236 165324 +88
Branches 38184 38194 +10
==========================================
+ Hits 130424 130548 +124
+ Misses 32350 32295 -55
- Partials 2462 2481 +19
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:
|
Code Review Agent Run #b18805Actionable 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 |
get_chart_sql had no extra_form_data field on its request schema, so any filters passed alongside a chart identifier were silently dropped before validation and the tool always rendered the chart's unfiltered baseline SQL. get_chart_data already merges extra_form_data correctly; this wires the same merge helpers into get_chart_sql's saved query_context and form_data fallback paths.
Adds coverage for the form_data_key-only path, closing a patch-coverage gap flagged on the extra_form_data fix.
Address PR review feedback: an extra_form_data filter entry missing a required key (e.g. "op") raised an unhandled KeyError out of get_chart_sql instead of a structured ChartError. Also use a keyword argument for extra_form_data at the _sql_from_form_data call site for clarity, and strengthen the saved-query_context regression tests to actually exercise both the "filters" and "adhoc_filters" extra_form_data formats (previously only "filters" was tested despite the docstring claiming both).
Filter merging on the saved query_context path needs the context's datasource id/type. Resolving those inside the same try as the merge meant a stale context (missing or malformed "datasource") was reported as "Invalid extra_form_data filter", skipping the form_data fallback so charts with valid params failed instead of rendering. Resolve the datasource up front and return None on failure so the caller rebuilds from form_data; keep the ValidationError for merge failures, which really are bad request filters. Also fixes the malformed-filter regression test, which still asserted the fallback path's "Invalid chart query data" message after the saved-context error branch was added. Co-Authored-By: Claude <noreply@anthropic.com>
503bd06 to
e1995f7
Compare
|
CI/review sweep complete:
Latest verified PR head: |
Code Review Agent Run #463d11Actionable 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 |
The unit-test job failed because the loaded query context test double did not match the QueryContext surface set_query_context_form_data consumes, so every saved-context case raised AttributeError instead of exercising the tool. Make the double serialize like a real QueryObject. Fixing that surfaced a real defect: ChartDataDatasourceSchema only requires "id", so a saved query_context that omits "type" loads fine but then raised an unhandled KeyError out of _sql_from_saved_query_context. Fall back to the chart's own datasource instead.
Code Review Agent Run #bc790bActionable 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 |
Recreates #43338, which GitHub auto-closed when its head fork was deleted. This version also rejects request filters that reference unknown dataset columns instead of returning unfiltered chart data.
SUMMARY
get_chart_sql's request schema had noextra_form_datafield. Pydantic silentlydrops unrecognized fields by default, so any filters passed alongside a chart
identifier were dropped before validation ever ran — the tool always rendered the
chart's unfiltered baseline SQL regardless of what was passed in.
get_chart_datamerges validextra_form_dataviamerge_extra_form_data_filters_into_query/build_query_context_from_form_data.However, datasource query construction reports filters naming unknown columns in
rejected_filter_columns, and the MCP tool previously ignored that signal andreturned the unfiltered result as a success. This PR intersects rejected columns
with the filters supplied by the current request and returns a
ValidationErrornaming them. It supports both
filtersandadhoc_filters, in saved-chart andform-data fallback paths, without failing on unrelated stale saved filters.
This PR also adds
extra_form_datatoGetChartSqlRequestand wires it into bothof
get_chart_sql's SQL-construction paths (savedquery_context, and theform_datafallback), reusing the existing merge helpers. The shared helper updatepreserves normalized relative-time extras (
relative_startandrelative_end) forboth chart-data and chart-SQL query construction.
TESTING INSTRUCTIONS
tests/unit_tests/mcp_service/chart/tool/test_get_chart_sql.py:GetChartSqlRequestaccepts and storesextra_form_data(previously silentlydropped).
_build_query_context_from_form_dataforwardsextra_form_datato the queryfactory.
_sql_from_saved_query_contextmergesextra_form_datainto the query handedto
ChartDataQueryContextSchema.loadbefore rendering SQL.request.extra_form_datareaches the saved-query_context SQLbuilder and shows up in the rendered SQL.
tests/unit_tests/mcp_service/chart/tool/test_get_chart_data.pycover valid
filters,adhoc_filters, andTEMPORAL_RANGEoverrides, plus thecustomer-reported unknown-column
adhoc_filterscase end-to-end through the MCPtool, asserting a named
ValidationErrorinstead of unfiltered chart data.form_dataon the query-context test double.pre-commit run --files <all PR-changed files>— clean locally and in CI.ADDITIONAL INFORMATION