fix(mcp): fall back to form_data spatial query for Deck.gl charts#40339
fix(mcp): fall back to form_data spatial query for Deck.gl charts#40339aminghadersohi wants to merge 1 commit into
Conversation
…t_data Deck.gl chart types (deck_scatter, deck_arc, deck_hex, etc.) use spatial column configs (lat/lon pairs, geohash, delimited coordinates) rather than the standard metrics/groupby structure. The get_chart_data MCP tool was returning an early MissingQueryContext error for these charts when no saved query_context was present, instead of falling back to form_data. - Add _deck_gl_spatial_cols and resolve_deck_gl_columns helpers to chart_helpers.py to extract SQL column names from spatial control configs (latlong, delimited, geohash) plus line_column, geojson, dimension, and js_columns fields. - Route deck_ viz types through the new helpers inside build_query_dicts_from_form_data, producing a raw-column or grouped-metric query matching BaseDeckGLViz.query_obj() semantics. - Remove the early-exit error block for deck_ charts in get_chart_data.py; the existing safety-net (empty columns + empty metrics) still guards charts whose spatial config is completely absent. - Add unit tests covering latlong, delimited, geohash, arc start/end, line_column, geojson, dimension, js_columns, deduplication, and the build_query_dicts_from_form_data Deck.gl branch.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #40339 +/- ##
==========================================
- Coverage 64.18% 64.11% -0.08%
==========================================
Files 2591 2592 +1
Lines 138459 138930 +471
Branches 32118 32223 +105
==========================================
+ Hits 88875 89069 +194
- Misses 48052 48329 +277
Partials 1532 1532
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Code Review Agent Run #7b748aActionable 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 |
SUMMARY
get_chart_dataMCP tool was returning aMissingQueryContexterror forDeck.gl charts (deck_scatter, deck_arc, deck_hex, etc.) when those charts had
no saved
query_context. Instead of offering a data retrieval path, the tooltold users to re-open and re-save the chart in Superset.
Deck.gl charts use spatial column configs (lat/lon pairs, geohash, delimited
coordinates, GeoJSON) rather than the standard
metrics/groupbystructure.This PR teaches the form_data fallback path how to extract those columns.
Changes:
Add
_deck_gl_spatial_cols(private helper) andresolve_deck_gl_columnsto
chart_helpers.py. The helper readsspatial,start_spatial,end_spatial,line_column,geojson,dimension, andjs_columnsfields from
form_dataand returns the SQL column names needed by theunderlying query — mirroring
BaseDeckGLViz.query_obj()semantics.Route
deck_*viz types through the new helpers insidebuild_query_dicts_from_form_data. When a size/metric field is present(e.g., point-radius or weight metric), it is included in the query; spatial
columns become the groupby dimensions. Without a metric, spatial columns
become raw-select columns.
Remove the hard error block in
get_chart_data.pythat rejected allDeck.gl charts with
MissingQueryContext. The existing safety-net (emptycolumns+ emptymetrics) still covers charts whose spatial config iscompletely missing.
Add unit tests covering: latlong, delimited, geohash spatial types;
arc start/end spatial;
line_column;geojson;dimension;js_columns; column deduplication; thebuild_query_dicts_from_form_dataDeck.gl branch with and without metrics.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A (backend-only change to MCP tool data retrieval)
TESTING INSTRUCTIONS
whose
paramsJSON has aspatialfield but no savedquery_context.get_chart_dataMCP tool with that chart's ID.ChartErrorwitherror_type: "MissingQueryContext"and amessage asking the user to re-save the chart.
geohash/delimited) columns from
form_dataand returns tabular data.Run the new unit tests:
pytest tests/unit_tests/mcp_service/chart/test_chart_helpers.py -x -q \ -k "deck"ADDITIONAL INFORMATION