Repository navigation
fix(mcp): disambiguate x_axis between column and axis styling - #42841
Conversation
XYChartConfig and MixedTimeseriesChartConfig accept ``x_axis`` as an alias for the x column while also exposing an ``x_axis`` AxisConfig field, so one input key fed both. That was tolerable while nested models ignored unknown fields; with strict checking the two readings collide and whichever model the payload does not fit rejects it. Route the key by shape instead: a bare string or a mapping naming no styling field is a column reference and moves to ``x``; anything else configures the axis. Naming the column twice is now an explicit error rather than a silent pick. This also fixes two payloads that were already broken: a bare string ``x_axis`` and an axis-styling ``x_axis`` sent without an explicit ``x``, both of which were rejected against the wrong model. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: DanRoscigno <[email protected]>
Code Review Agent Run #ebce24Actionable Suggestions - 0Filtered by Review RulesBito filtered these suggestions based on rules created automatically for your feedback. Manage rules.
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. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #42841 +/- ##
===========================================
+ Coverage 65.38% 84.69% +19.31%
===========================================
Files 3069 3069
Lines 205465 205486 +21
Branches 48310 48313 +3
===========================================
+ Hits 134336 174034 +39698
+ Misses 68043 28162 -39881
- Partials 3086 3290 +204
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:
|
aminghadersohi
left a comment
There was a problem hiding this comment.
Summary
The disambiguation is correct and well-scoped. One low-severity heuristic edge is noted inline; nothing blocking.
Both senses separated everywhere the key is read. The x_axis/styling collision only exists in the two configs that expose x_axis as both a column alias and an AxisConfig styling field — XYChartConfig (schemas.py:1747) and MixedTimeseriesChartConfig (schemas.py:1245). Both now route through _route_x_axis_key, and the x/x_axis alias overload is removed from each. WaterfallChartConfig (schemas.py:2048) is correctly left alone: there x_axis is unambiguously the ColumnRef column (no styling field), and its existing unwrap_list_breakdown already coerces a bare-string x_axis. No sibling styling key (x_axis_time_format, x_axis_label) is overloaded — those are plain scalar fields. So the split is complete.
Frontend ground-truth. In native form_data, x_axis is the x-axis column control (dndXAxisControl, superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx:509; wired in echartsTimeSeriesQuery.tsx:44,51), while axis styling lives under distinct keys (x_axis_time_format, x_axis_label). The frontend never collides these, so the nested x_axis: AxisConfig object is an MCP-only convenience — routing a bare/column-shaped x_axis to the x column matches what the plugin actually consumes.
Backward-compat on saved charts. No regression. Under the old code the x_axis: AxisConfig field name won over the AliasChoices("x", "x_axis") alias, so a column-shaped x_axis was already rejected for these two types (reverting only the production change and running the new tests reproduces Unknown field 'name'). The fix repairs that path; a bare-string x_axis still lands on x. No previously-working payload changes meaning.
Strictness interaction. The UnknownFieldCheckMixin before-validator composes cleanly — both x and x_axis are known fields, so nothing that validated before is newly rejected, and a mistyped styling key still surfaces against AxisConfig (tested).
Tests. TestXAxisRouting pins the disambiguation itself in both directions (column-shaped → x with x_axis is None; styling-shaped → x_axis populated with x is None), covers the bare-string native-form_data shape, and the double-column-reference rejection. Reverting only the production change fails 6 of the 10 cases, so the suite is non-vacuous; expected values are literals, not implementation-derived.
|
The heuristic in This behavior is indeed a boundary of the current implementation. While it surfaces an 'Unknown field' error against the column rather than the styling config, this is consistent with the heuristic's design to prioritize column routing when no valid styling fields are detected. Given that such a payload is functionally unusable, this trade-off is acceptable for the current scope. superset/mcp_service/chart/schemas.py |
|
Thanks @DanRoscigno, routing |
aminghadersohi
left a comment
There was a problem hiding this comment.
A bare-string x_axis still fails on mixed_timeseries, and one new test passes without the fix.
Co-authored-by: Amin Ghadersohi <[email protected]>
Co-authored-by: Amin Ghadersohi <[email protected]>
Signed-off-by: DanRoscigno <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: Evan Rusackas <[email protected]> Co-authored-by: Amin Ghadersohi <[email protected]>
On 7.0 XYChartConfig.x also drops its x_axis alias, as master already had, so a styling-shaped x_axis reaches the axis field. Signed-off-by: DanRoscigno <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: Evan Rusackas <[email protected]> Co-authored-by: Amin Ghadersohi <[email protected]> (cherry picked from commit 842bad2)
SUMMARY
XYChartConfigandMixedTimeseriesChartConfigacceptx_axisas a validation alias for the x column — nativeform_datanames the column that way — while also declaring a separatex_axis: AxisConfigstyling field. One input key fed both fields.That was survivable while nested models ignored unknown keys: a column dict sent as
x_axissetxand quietly built an unused emptyAxisConfig. Since #42732 made the nested models reject unknown fields, whichever of the two models the payload does not fit now rejects it. Probing current master,XYChartConfigwith no explicitx:x_axis: {"name": "category"}Unknown field 'name'. Valid fields: format, scale, titlexx_axis: "category"Input should be a valid dictionary or instance of AxisConfigxx_axis: {"title": "State"}Unknown field 'title'. Valid fields: aggregate, column_name, dtype, ...The first is a regression from #42732 — that payload worked before it merged. The other two predate it. The common thread is that every spelling of
x_axisis now rejected on these two chart types, and each error names the model the caller wasn't thinking about, which is the opposite of what the unknown-field checking is for.#42732 met this same collision in
test_known_aliases_not_flagged_as_unknownand worked around it by switching that test tox_column, documenting the ambiguity in the docstring. This PR removes the ambiguity instead.x_axisis now routed by shape in amodel_validator(mode="before"), and dropped fromx'sAliasChoicesso it no longer feeds both fields. A bare string, or a mapping naming noAxisConfigfield, is a column reference and moves tox; anything else configures the axis. Supplying the column twice (xplus a column-shapedx_axis) is now an explicit error rather than a silent pick.Keying that check off the styling names rather than the column names is deliberate — it keeps a mistyped styling key reported against the model the caller meant:
{"x_axis": {"title": "State", "sort_by": "metric"}} # -> Unknown field 'sort_by'. Valid fields: format, scale, title {"x_axis": {"name": "category", "aggregat": "SUM"}} # -> Unknown field 'aggregat' — did you mean 'aggregate'?I checked every model in
schemas.pyfor the same field-name/alias overlap;x_axison these two classes is the only instance.Worth a reviewer's eye:
test_mixed_timeseries_pre_validate_accepts_x_axis_aliason master asserts thex_axisalias is accepted, and passes today only becausepre_validateinspects the raw dict and never constructs the model. It keeps passing here, and now the model behind it agrees.TESTING INSTRUCTIONS
New
TestXAxisRoutingcovers both chart types: column-shapedx_axis(dict,column_namealias, bare string), styling-shapedx_axis, both supplied together, the column-named-twice rejection, and that a mistyped key is reported against whichever model the payload was meant for.Verified locally against this branch:
pytest tests/unit_tests/mcp_service/chart— 1182 passedpytest tests/unit_tests/mcp_service— 3326 passed, 1 failed:test_mcp_e2e_smoke.py::test_tools_call_health_check_over_real_asgi_transport, which fails identically on clean master and is unrelated to this changepre-commit run --files superset/mcp_service/chart/schemas.py tests/unit_tests/mcp_service/chart/test_chart_schemas.py— all hooks pass, including mypy, ruff and pylintTo see the current behaviour before the fix, on master:
ADDITIONAL INFORMATION
🤖 Generated with Claude Code