Skip to content

fix(mcp): disambiguate x_axis between column and axis styling - #42841

Merged
sadpandajoe merged 6 commits into
apache:masterfrom
DanRoscigno:fix/mcp-x-axis-collision
Nov 10, 2026
Merged

sadpandajoe merged 6 commits into
apache:masterfrom
DanRoscigno:fix/mcp-x-axis-collision

Conversation

@DanRoscigno

Copy link
Copy Markdown
Contributor

SUMMARY

XYChartConfig and MixedTimeseriesChartConfig accept x_axis as a validation alias for the x column — native form_data names the column that way — while also declaring a separate x_axis: AxisConfig styling field. One input key fed both fields.

That was survivable while nested models ignored unknown keys: a column dict sent as x_axis set x and quietly built an unused empty AxisConfig. 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, XYChartConfig with no explicit x:

payload master with this PR
x_axis: {"name": "category"} Unknown field 'name'. Valid fields: format, scale, title sets x
x_axis: "category" Input should be a valid dictionary or instance of AxisConfig sets x
x_axis: {"title": "State"} Unknown field 'title'. Valid fields: aggregate, column_name, dtype, ... sets the axis

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_axis is 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_unknown and worked around it by switching that test to x_column, documenting the ambiguity in the docstring. This PR removes the ambiguity instead.

x_axis is now routed by shape in a model_validator(mode="before"), and dropped from x's AliasChoices so it no longer feeds both fields. A bare string, or a mapping naming no AxisConfig field, is a column reference and moves to x; anything else configures the axis. Supplying the column twice (x plus a column-shaped x_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.py for the same field-name/alias overlap; x_axis on these two classes is the only instance.

Worth a reviewer's eye: test_mixed_timeseries_pre_validate_accepts_x_axis_alias on master asserts the x_axis alias is accepted, and passes today only because pre_validate inspects the raw dict and never constructs the model. It keeps passing here, and now the model behind it agrees.

TESTING INSTRUCTIONS

New TestXAxisRouting covers both chart types: column-shaped x_axis (dict, column_name alias, bare string), styling-shaped x_axis, both supplied together, the column-named-twice rejection, and that a mistyped key is reported against whichever model the payload was meant for.

pytest tests/unit_tests/mcp_service/chart/test_chart_schemas.py -k XAxisRouting

Verified locally against this branch:

  • pytest tests/unit_tests/mcp_service/chart — 1182 passed
  • pytest 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 change
  • pre-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 pylint

To see the current behaviour before the fix, on master:

XYChartConfig.model_validate({
    "chart_type": "xy",
    "y": [{"name": "sales", "aggregate": "SUM"}],
    "x_axis": {"name": "category"},
})
# ValidationError: Unknown field 'name'. Valid fields: format, scale, title

ADDITIONAL INFORMATION

🤖 Generated with Claude Code

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]>
@dosubot dosubot Bot added the viz:charts Namespace | Anything related to viz types label Aug 6, 2026
@bito-code-review

bito-code-review Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #ebce24

Actionable Suggestions - 0
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • tests/unit_tests/mcp_service/chart/test_chart_schemas.py - 1
Review Details
  • Files reviewed - 2 · Commit Range: 8089a70..8089a70
    • superset/mcp_service/chart/schemas.py
    • tests/unit_tests/mcp_service/chart/test_chart_schemas.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

AI Code Review powered by Bito Logo

@netlify

netlify Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit ebc320c
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a74bb4dde04ea00085aca28
😎 Deploy Preview https://deploy-preview-42841--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.69%. Comparing base (5735bdb) to head (35dc433).
⚠️ Report is 1 commits behind head on master.

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     
Flag Coverage Δ
hive 34.53% <36.36%> (-0.01%) ⬇️
mysql 52.55% <36.36%> (?)
postgres 52.55% <36.36%> (?)
presto 36.26% <36.36%> (-0.01%) ⬇️
python 87.73% <100.00%> (+35.30%) ⬆️
sqlite 52.32% <36.36%> (-0.01%) ⬇️
unit 82.45% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aminghadersohi aminghadersohi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread superset/mcp_service/chart/schemas.py Resolved
@bito-code-review

Copy link
Copy Markdown
Contributor

The heuristic in _route_x_axis_key correctly identifies the edge case you described. Because the logic relies on set(value) & set(AxisConfig.model_fields) to determine if a dictionary is styling, a payload with only mistyped keys (e.g., {"titel": "State"}) will result in an empty intersection, causing the heuristic to treat it as a column reference and route it to x.

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

is_column_ref = isinstance(value, str) or (
        isinstance(value, dict)
        and bool(value)
        and not set(value) & set(AxisConfig.model_fields)
    )

@github-actions github-actions Bot added requires:rebase Requires rebasing on top of current master and removed requires:rebase Requires rebasing on top of current master labels Oct 9, 2026
@rusackas

Copy link
Copy Markdown
Member

Thanks @DanRoscigno, routing x_axis by payload shape is a sensible way out of the double-duty key, and the tests cover the cases well. LGTM from me once you've decided what to do with @aminghadersohi's nit about all-mistyped styling keys (fine to leave as is if it's rare, but safer is always better).

@codeant-ai-for-open-source

codeant-ai-for-open-source Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟢  Low Risk

  • The PR appears safe to merge; no actionable issues were identified in the review.

Assessed commit: 16ec9a949bd3

@aminghadersohi aminghadersohi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bare-string x_axis still fails on mixed_timeseries, and one new test passes without the fix.

Comment thread superset/mcp_service/chart/schemas.py Resolved
@sadpandajoe
sadpandajoe merged commit 842bad2 into apache:master Nov 10, 2026
74 checks passed
hainenber pushed a commit that referenced this pull request Nov 14, 2026
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]>
villebro pushed a commit that referenced this pull request Nov 14, 2026
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)
@github-actions github-actions Bot added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.20.2 First shipped in 0.20.2 labels Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/L viz:charts Namespace | Anything related to viz types 🚢 0.20.2 First shipped in 0.20.2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants