Repository navigation
fix(mcp): reject unknown fields in nested chart-config models - #42628
DanRoscigno wants to merge 5 commits into
Conversation
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]>
Code Review Agent Run #8bc223Actionable 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
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:
|
|
@DanRoscigno, CI's failing, if you have some time to tend to it. |
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]>
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Code Review Agent Run #446477Actionable 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 |
|
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 #42732 met the same collision in |
SUMMARY
UnknownFieldCheckMixininsuperset/mcp_service/chart/schemas.pyexists to stop unknown fields being silently dropped:All ten top-level chart config models inherit it. The nested models they are composed of do not —
ColumnRef,AxisConfig,LegendConfig,CurrencyFormat,FilterConfigandSortByConfigare plainBaseModel, so pydantic's defaultextra="ignore"applies one level down.The result is that unknown-field protection stops at exactly one level of nesting:
Through the tools this is worse than a plain rejection:
update_chartreturnssuccess: truewith a chart URL and no warnings, while the storedform_datais unchanged. A client — human or agent — reasonably concludes the setting was applied, and confirming otherwise requires a follow-upget_chart_infoplus knowledge of which nativeform_datakey 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_fieldsis already generic overmodel_classand resolves aliases through_get_known_fields, so no other change was needed and existing aliases (column_name,col,opr,val) keep working.The
x_axiscollisionStrict nested checking surfaced a pre-existing ambiguity that had to be resolved for this change to work.
XYChartConfigandMixedTimeseriesChartConfigacceptx_axisas a validation alias for the x column (nativeform_datanames the column that way) and declare a separatex_axis: AxisConfigstyling 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_axisis now routed by shape in amodel_validator(mode="before"), and dropped fromx'sAliasChoicesso it no longer feeds both. 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
AxisConfig, where the caller meant it.{"x_axis": {"title": "State", "sort_by": "metric"}} # -> Unknown field 'sort_by'. Valid fields: format, scale, titleBehaviour for a payload with no explicit
x, on these two chart types only:x_axis: {"name": "category"}AxisConfig)xx_axis: "category"AxisConfigxx_axis: {"title": "State"}ColumnRefThe 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_axison 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_axisoverlap above, nothing internal relies on the lax behaviour — there are noModel(**kwargs)constructions, no directmodel_validatecalls, and no subclasses of these six models anywhere insuperset/.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 modelstest_unknown_field_nested_in_axis_config_rejected— through the real nesting path viaXYChartConfigtest_nested_aliases_still_accepted— guards the alias behaviour that is the main regression riskAnd a new
TestXAxisRoutingclass covering both chart types: column-shapedx_axis(dict,column_namealias, and 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.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):
generate_chartanxybar chart and notex_axis_sort_series_type: "name"in the savedform_dataupdate_chartwithconfig.x_axis = {"title": "...", "sort_by": "metric"}success: true;get_chart_infoshowsform_dataunchangedUnknown field 'sort_by'. Valid fields: format, scale, titleI 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.CurrencyFormatandSortByConfigdo not exist in 6.1.0, so those two were exercised only by the new unit tests.ruff checkandruff formatare 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 tonow - 1h, so between 00:00 and 01:59 it lands at or before the default until oftodayandget_since_until()returns instead of raising. The job started at 01:16 UTC. Fixed separately by pinning the clock in that test.ADDITIONAL INFORMATION