Skip to content

fix(mcp): reject unknown fields in nested chart-config models - #42628

Closed
DanRoscigno wants to merge 5 commits into
apache:masterfrom
DanRoscigno:fix/mcp-nested-config-unknown-fields
Closed

DanRoscigno wants to merge 5 commits into
apache:masterfrom
DanRoscigno:fix/mcp-nested-config-unknown-fields

Conversation

@DanRoscigno

@DanRoscigno DanRoscigno commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

SUMMARY

UnknownFieldCheckMixin in superset/mcp_service/chart/schemas.py exists to stop unknown fields being silently dropped:

Catches fields that would be silently dropped by extra='ignore' and provides actionable error messages to help LLMs self-correct parameter names.

All ten top-level chart config models inherit it. The nested models they are composed of do not — ColumnRef, AxisConfig, LegendConfig, CurrencyFormat, FilterConfig and SortByConfig are plain BaseModel, so pydantic's default extra="ignore" applies one level down.

The result is that unknown-field protection stops at exactly one level of nesting:

# rejected — "Unknown field 'sort_by'. Valid fields: ..."
parse_chart_config({**base, "sort_by": "metric"})

# accepted, silently discarded
parse_chart_config({**base, "x_axis": {"title": "State", "sort_by": "metric"}})
# -> AxisConfig(title='State', scale='linear', format=None)

Through the tools this is worse than a plain rejection: update_chart returns success: true with a chart URL and no warnings, while the stored form_data is unchanged. A client — human or agent — reasonably concludes the setting was applied, and confirming otherwise requires a follow-up get_chart_info plus knowledge of which native form_data key the config field maps to. An agent that self-corrects on error has nothing to correct against.

This PR makes the six nested models inherit the mixin so they produce the same "did you mean?" errors as top-level configs.

_check_unknown_fields is already generic over model_class and resolves aliases through _get_known_fields, so no other change was needed and existing aliases (column_name, col, opr, val) keep working.

The x_axis collision

Strict nested checking surfaced a pre-existing ambiguity that had to be resolved for this change to work. XYChartConfig and MixedTimeseriesChartConfig accept x_axis as a validation alias for the x column (native form_data names the column that way) and declare a separate x_axis: AxisConfig styling field. One input key fed both fields. That was survivable while nested models ignored unknown keys; with strict checking, whichever of the two models the payload does not fit rejects it.

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. 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 AxisConfig, where the caller meant it.

{"x_axis": {"title": "State", "sort_by": "metric"}}
# -> Unknown field 'sort_by'. Valid fields: format, scale, title

Behaviour for a payload with no explicit x, on these two chart types only:

payload before this PR with this PR
x_axis: {"name": "category"} accepted (also built an unused empty AxisConfig) accepted, sets x
x_axis: "category" rejected against AxisConfig accepted, sets x
x_axis: {"title": "State"} rejected against ColumnRef accepted, sets the axis

The last two were already broken on master; they are fixed here because leaving them broken while tightening the nested models would have made the errors harder to act on, not easier. I checked every model in the file for the same field-name/alias overlap — x_axis on these two classes is the only instance.

Behaviour change worth a reviewer's attention: payloads carrying extra keys inside nested objects now fail instead of being silently accepted. That is the mixin's stated intent and matches existing top-level behaviour, but it is a change for any client currently sending extras. Beyond the x_axis overlap above, nothing internal relies on the lax behaviour — there are no Model(**kwargs) constructions, no direct model_validate calls, and no subclasses of these six models anywhere in superset/.

TESTING INSTRUCTIONS

Added to tests/unit_tests/mcp_service/chart/test_chart_schemas.py::TestUnknownFieldDetection:

  • test_nested_models_reject_unknown_fields — parametrized over all six models
  • test_unknown_field_nested_in_axis_config_rejected — through the real nesting path via XYChartConfig
  • test_nested_aliases_still_accepted — guards the alias behaviour that is the main regression risk

And a new TestXAxisRouting class covering both chart types: column-shaped x_axis (dict, column_name alias, and 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 "UnknownField or XAxisRouting"

Manual check against a running instance (Superset 6.1.0, StarRocks-backed virtual dataset):

  1. generate_chart an xy bar chart and note x_axis_sort_series_type: "name" in the saved form_data
  2. update_chart with config.x_axis = {"title": "...", "sort_by": "metric"}
  3. Before: returns success: true; get_chart_info shows form_data unchanged
  4. After: rejected with Unknown field 'sort_by'. Valid fields: format, scale, title

I verified the patched classes against the 6.1.0 runtime by loading a patched copy of its own schemas.py — nested unknown fields are rejected, aliases (column_name → name, col → column) still resolve, and valid nested configs are still accepted. CurrencyFormat and SortByConfig do not exist in 6.1.0, so those two were exercised only by the new unit tests. ruff check and ruff format are clean on both files. I did not have a full Superset dev environment available to run the whole unit suite locally, so I'm relying on CI for that.

Note on the earlier red build: two of the three failures were TestValidateTimeRangeSubDayLast::test_sub_day_last_normalizes[Last hour] / [Last Hour], which are unrelated to this PR and are inherited from master. That test's premise assertion depends on the wall time — parsedatetime resolves a bare "Last hour" to the top of the previous hour rather than to now - 1h, so between 00:00 and 01:59 it lands at or before the default until of today and get_since_until() returns instead of raising. The job started at 01:16 UTC. Fixed separately by pinning the clock in that test.

ADDITIONAL INFORMATION

UnknownFieldCheckMixin is applied to all ten top-level chart config
models but not to the nested models they are composed of, so pydantic's
default extra="ignore" applies one level down. An unknown field inside
x_axis, x, legend or filters is silently dropped while the tool still
reports success, so a client has no signal that the setting was not
applied. The mixin exists specifically to prevent that.

Make ColumnRef, AxisConfig, LegendConfig, CurrencyFormat, FilterConfig
and SortByConfig inherit the mixin so nested fields produce the same
"did you mean?" errors as top-level ones. _check_unknown_fields is
already generic over model_class and resolves AliasChoices, so existing
aliases (column_name, col, opr, val) keep working.

Closes apache#42626

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Dan Roscigno <[email protected]>
@dosubot dosubot Bot added the risk:breaking-change Issues or PRs that will introduce breaking changes label Jul 31, 2026
@bito-code-review

bito-code-review Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #8bc223

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 - 6
Review Details
  • Files reviewed - 2 · Commit Range: 8a2614d..8a2614d
    • 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

@codecov

codecov Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.19%. Comparing base (da27b4e) to head (4249ac8).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #42628      +/-   ##
==========================================
- Coverage   65.19%   65.19%   -0.01%     
==========================================
  Files        2841     2841              
  Lines      162079   162068      -11     
  Branches    37144    37137       -7     
==========================================
- Hits       105673   105659      -14     
- Misses      54342    54344       +2     
- Partials     2064     2065       +1     
Flag Coverage Δ
hive 38.07% <100.00%> (ø)
mysql 57.90% <100.00%> (ø)
postgres 57.94% <100.00%> (-0.01%) ⬇️
presto 40.00% <100.00%> (ø)
python 58.16% <100.00%> (-0.01%) ⬇️
sqlite 57.57% <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.

@rusackas

rusackas commented Aug 5, 2026

Copy link
Copy Markdown
Member

@DanRoscigno, CI's failing, if you have some time to tend to it. test_known_aliases_not_flagged_as_unknown in the same file breaks under the stricter check, since its x_axis payload uses name where it should be title (previously just got silently dropped, now it's a real error, which seems like a good thing to catch). Probably needs a fix there before this can merge.

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]>
@netlify

netlify Bot commented Aug 6, 2026

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 8cce669
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a73d03ddd41f20008de69be
😎 Deploy Preview https://deploy-preview-42628--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.

@bito-code-review

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

Copy link
Copy Markdown
Contributor

Code Review Agent Run #446477

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 8a2614d..8cce669
    • 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

@DanRoscigno

Copy link
Copy Markdown
Contributor Author

Superseded by #42732, which landed the same nested unknown-field change for #42626.

Closing in favour of #42841, which carries the one part of this PR that isn't covered there: the x_axis collision on XYChartConfig and MixedTimeseriesChartConfig. Those two classes accept x_axis as an alias for the x column and declare an x_axis: AxisConfig styling field, so one input key feeds both. Harmless while nested models ignored unknown keys; with strict checking every spelling of x_axis is now rejected on those chart types, including x_axis: {"name": "category"}, which worked before #42732.

#42732 met the same collision in test_known_aliases_not_flagged_as_unknown and routed around it via x_column, documenting the ambiguity. #42841 removes it, so both readings work again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:breaking-change Issues or PRs that will introduce breaking changes size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants