Repository navigation
fix(mcp): reject unknown fields in nested chart-config models too (#42626) - #42732
Conversation
Only the 10 top-level chart config models (PieChartConfig, XYChartConfig, etc.) inherit UnknownFieldCheckMixin. Nested sub-models they're composed of -- AxisConfig, LegendConfig, CurrencyFormat, FilterConfig, SortByConfig, ColumnRef -- are plain BaseModel, so pydantic's default extra="ignore" silently drops a typo'd field one level down instead of raising the same "did you mean?" error a top-level typo gets. This is worse than a plain rejection for an MCP client (especially an LLM driving one): update_chart returns success:true with no warnings, so the caller has no signal the setting it just sent was silently dropped. Currently red: AxisConfig.model_validate() with an unknown field succeeds today instead of raising, documenting the gap until the nested models pick up UnknownFieldCheckMixin too.
Code Review Agent Run #1e07cbActionable 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #42732 +/- ##
==========================================
- Coverage 65.57% 65.01% -0.56%
==========================================
Files 2818 2819 +1
Lines 160038 160168 +130
Branches 36557 36569 +12
==========================================
- Hits 104942 104135 -807
- Misses 53051 53984 +933
- Partials 2045 2049 +4
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:
|
…2626) Only the 10 top-level chart config models inherited UnknownFieldCheckMixin; nested sub-models (ColumnRef, AxisConfig, LegendConfig, CurrencyFormat, FilterConfig, SortByConfig) were plain BaseModel, so a typo'd field one level down was silently dropped by pydantic's default extra="ignore" instead of raising the same "did you mean?" error a top-level typo gets. Give every nested config the same mixin and extra="ignore" config the top-level models already use. This also surfaces a separate, pre-existing wrinkle: XYChartConfig.x has x_axis as a validation_alias, which collides with the model's own x_axis: AxisConfig field of the same name -- pydantic resolves that collision in favor of the real field name, so routing a column through the x_axis alias silently landed in (and, before this fix, was silently swallowed by) AxisConfig instead of populating x. That's a separate bug in the alias design, left as a known follow-up rather than fixed here; the one existing test that exercised it was updated to use the unambiguous x_column alias instead.
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Code Review Agent Run #680585Actionable 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 |
aminghadersohi
left a comment
There was a problem hiding this comment.
Checked whether the added extra="ignore" could blind the check. It cannot: UnknownFieldCheckMixin.check_unknown_fields is a @model_validator(mode="before"), so it inspects the raw input dict before pydantic applies extra. extra="ignore" only governs what pydantic does with fields that survive the validator, which runs first. I reproduced the exact mixin pattern standalone on pydantic 2.11.7 (the full app import chain isn't available in my env, so this is a faithful replica of the model shape, not the imported class): mixin + extra="ignore" raises on an unknown key identically to extra="allow", and valid input is unaffected. So the rejection fires as intended — not a no-op.
Completeness: every nested model used as an input field on the chart-config classes now inherits the mixin — ColumnRef, AxisConfig, LegendConfig, CurrencyFormat, FilterConfig, SortByConfig. I found no sibling nested config model left as a plain BaseModel (TimeGrain is an enum; AdhocFilter/DataColumn are output/parse-side models, not tool inputs).
Behavior: stricter contract — a key that pydantic's default extra="ignore" previously dropped silently now raises a ValidationError with a "did you mean?" hint. Those keys were already discarded (never used), so no well-formed caller regresses; a typo now surfaces instead of no-op'ing, which is the intent of #42626.
Note: #42628 targets the same fix by adding the mixin without an explicit extra="ignore" (relying on pydantic's default). This PR is the more explicit of the two; merging both would conflict on the same lines.
Tests: the new test_unknown_field_nested_one_level_down_is_rejected asserts directly on the nested AxisConfig (the model that got the mixin), not on a top-level extra="forbid" model, so it exercises the actual change. Reasoning about the revert: pre-fix AxisConfig is a plain BaseModel under pydantic's default extra="ignore", which I reproduced standalone drops the unknown key without raising — so reverting the production change makes this test fail by construction (I did not run the repo test suite in-env).
|
@aminghadersohi thanks for digging into whether On #42628, that's DanRoscigno's version of the same fix, but CI's red over there. We may want to close it in favor of this one once this passes. |
SUMMARY
Fixes #42626: only the 10 top-level MCP chart config models (
PieChartConfig,XYChartConfig, etc.) inheritedUnknownFieldCheckMixin, which rejects unknown fields with a "did you mean?" suggestion. The nested sub-models they're composed of —AxisConfig,LegendConfig,CurrencyFormat,FilterConfig,SortByConfig,ColumnRef— were plainBaseModel, so pydantic's defaultextra="ignore"silently dropped a typo'd field one level down instead of raising.This was worse than a plain rejection for an MCP client (especially an LLM driving one):
update_chartwould returnsuccess: truewith no warnings, so the caller had no signal the setting it just sent was silently dropped. The reporter's own repro showed three successiveupdate_chartcalls each returning success while changing nothing.Fix. Give every nested config model the same
UnknownFieldCheckMixin(and matchingextra="ignore"config) the top-level models already use, since the mixin itself has no top-level-specific assumptions — it just inspectsmodel_fieldson whatever class it's mixed into.A separate, pre-existing wrinkle this surfaced, left as a follow-up (not fixed here):
XYChartConfig.xdeclaresx_axisas one of itsvalidation_aliaschoices, but the model also has its own field literally namedx_axis: AxisConfig. That's a real alias/field-name collision — pydantic resolves it in favor of the actual field name, so a column dict sent through thex_axiskey was always routed intox_axis: AxisConfig, not intox: ColumnRefas the alias implies. Before this fix that silently no-op'd (extra fields ignored); after this fix it would raise "Unknown field" for anyColumnRef-shaped payload sent that way. The one existing test that happened to rely on this (test_known_aliases_not_flagged_as_unknown) has been updated to use the unambiguousx_columnalias instead, but the underlying alias collision onXYChartConfigitself is untouched — worth its own follow-up if it's confusing clients in practice.TESTING INSTRUCTIONS
test_unknown_field_nested_one_level_down_is_rejectednow passes (green). Fullmcp_serviceunit suite (3132 tests, excluding the e2e ASGI-transport smoke file, which is unrelated and flaky under heavy parallel load) passes with no regressions.ADDITIONAL INFORMATION