Repository navigation
fix(mcp): preserve chart form data on update - #43679
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #43679 +/- ##
===========================================
+ Coverage 66.49% 80.12% +13.63%
===========================================
Files 2923 2923
Lines 172121 172211 +90
Branches 39952 39980 +28
===========================================
+ Hits 114445 137981 +23536
+ Misses 55300 31642 -23658
- Partials 2376 2588 +212
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:
|
364f479 to
b47bd4a
Compare
b47bd4a to
4a655cd
Compare
4a655cd to
93f4934
Compare
Code Review Agent Run #14e8c5Actionable 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 |
gabotorresruiz
left a comment
There was a problem hiding this comment.
Thanks for this fix Amin, the preview/save unification is the right call and the regression tests are solid. I ran the full mcp_service unit suite on this branch (3722 passed) and verified the two new save-path tests fail on master, so they genuinely pin the fix. Two non-blocking comments inline where the merge semantics still surprise, plus one question on dataset rebinds. None of them block merging for me.
Code Review Agent Run #82b639Actionable Suggestions - 0Additional Suggestions - 3
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 |
…eserve-form-data # Conflicts: # superset/mcp_service/chart/tool/update_chart.py # superset/mcp_service/chart/tool/update_chart_preview.py # tests/unit_tests/mcp_service/chart/tool/test_update_chart_preview.py
|
Addressed the three follow-up suggestions in 36307ce and reconciled the branch with master in 4b00500. Dataset rebind validation now ignores explicitly supplied clears, removes only incompatible inherited query fields, and retains unrelated presentation/custom state. Filter deduplication compares comparator values for ordinary filters while preserving the intended single generated temporal binding. Focused regressions cover explicit-empty rebinds, granular incompatible-state pruning, and distinct comparators. Post-merge pre-commit checks (mypy, ruff, pylint, and formatting) pass on all five changed Python files. |
The previous merge resolution reinstated a local copy of the update merge logic, which dropped the shared merge_chart_form_data helper and its Gauge handling. Restore the shared helper and re-apply the preservation behavior on top of it: - Non-Gauge dataset rebinds discard only the inherited state that cannot resolve against the replacement dataset, instead of resetting the chart wholesale. Gauge keeps its stricter presentation-only rebind. - Saved adhoc filters survive an update that does not mention filters, while mapper-generated bindings are still appended. - An explicitly empty group_by, group_by_secondary or sort_by clears the control rather than inheriting the previous value. Also corrects a stale assertion in test_merges_existing_params_with_new _config, whose fixture had been changed to a same-viz update while still asserting the cross-viz drop; cross-viz behavior remains covered by test_config_update_does_not_merge_settings_from_another_viz_type. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Bito Automatic Review Skipped – PR Already Merged |
| if dataset_rebind: | ||
| return dict(new_form_data) | ||
| fields_set = config.model_fields_set | ||
| if "filters" not in fields_set: |
There was a problem hiding this comment.
Thanks for the follow-up Amin, the per-key rebind preservation is a clear improvement over blanking everything. One problem remains though: the "filters" not in fields_set gate (now in merge_chart_form_data) does not survive column normalization. update_chart reassigns parsed_config from DatasetValidator.normalize_column_names, and every plugin except gauge round-trips the config through a full model_dump() then model_validate(), which marks every field as set. Gauge dodges it because its normalize_column_refs uses model_dump(exclude_unset=True); XY, table, mixed_timeseries and the rest do not. I verified it on this branch: passing _build_update_payload a config round-tripped that way (the shape the tool produces whenever the dataset resolves) skips preserve_previous_adhoc_filters and drops a saved country = US predicate again, while the same call with the un-normalized config preserves it. The tests all build configs from sparse dicts, so they only exercise the un-normalized shape.
Two ways to close it: gate on the value instead, which is immune to normalization,
if getattr(config, "filters", None) is None:
preserve_previous_adhoc_filters(new_form_data, existing_form_data)or switch the remaining plugins to model_dump(exclude_unset=True) like gauge. Either way, a regression test that round-trips the config through model_validate(config.model_dump()) before calling _build_update_payload would pin the production path. The explicit-empty pops are fine as-is since they compare values.
| against the replacement dataset; everything else stays valid and is | ||
| preserved so the update does not silently reset the chart. | ||
| """ | ||
| fields_set = parsed_config.model_fields_set |
There was a problem hiding this comment.
Same normalization issue reaches the rebind check: _inherited_state_invalid_keys excludes a key from the inherited set whenever its config field is in model_fields_set, and after normalize_column_names every field is. I verified on this branch that a rebind whose saved params carry only an incompatible adhoc filter never consults the target dataset and still lands old_ds_col in the merged params with a round-tripped config, so the "rejection names a column the caller never sent" failure mode is still reachable. The is None value test (or the exclude_unset normalization fix) closes this one too; the per-key preservation logic itself checks out, including the fail-safe when the replacement dataset cannot be inspected.
SUMMARY
Make
update_chart's immediate-save path merge simplified configuration changes onto the chart's existingform_data, matching the preview path. This preserves visualization settings outside the MCP configuration schema while honoring explicitly empty filters, grouping, and sorting.Replacement form-data construction is shared by preview and save to prevent drift. Temporal updates retain omitted non-temporal predicates alongside mapper-generated temporal filters. Existing settings are preserved only for same-type updates, and dataset rebinds retain compatible inherited query state field-by-field while dropping only references that are invalid for the replacement dataset. Dataset-independent presentation state remains intact. The datasource stored in
paramsis also kept consistent with the chart'sdatasource_id.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Not applicable; this is an MCP persistence fix with no direct UI change.
TESTING INSTRUCTIONS
update_chartwithgenerate_preview=false, changing its metrics throughconfigwhile omitting filters.group_byand tablesort_byvalues clear the corresponding saved fields.params.datasource.Automated validation performed:
118 passedacrosstest_update_chart.pyandtest_update_chart_preview.py1393 passedacrosstests/unit_tests/mcp_service/chart/pre-commit run(all applicable hooks passed)ADDITIONAL INFORMATION