Skip to content

fix(mcp): preserve chart form data on update - #43679

Merged
aminghadersohi merged 9 commits into
masterfrom
mcp-update-chart-preserve-form-data
Sep 9, 2026
Merged

aminghadersohi merged 9 commits into
masterfrom
mcp-update-chart-preserve-form-data

Conversation

@aminghadersohi

@aminghadersohi aminghadersohi commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

SUMMARY

Make update_chart's immediate-save path merge simplified configuration changes onto the chart's existing form_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 params is also kept consistent with the chart's datasource_id.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Not applicable; this is an MCP persistence fix with no direct UI change.

TESTING INSTRUCTIONS

  1. Create a mixed time-series chart whose saved params include time comparison, a non-temporal predicate, and formatting settings.
  2. Call update_chart with generate_preview=false, changing its metrics through config while omitting filters.
  3. Confirm the updated params contain the new metrics and retain the omitted predicate, time comparison, and formatting settings, matching preview behavior.
  4. Verify explicit empty group_by and table sort_by values clear the corresponding saved fields.
  5. Verify changing visualization types does not retain query settings from the previous type.
  6. Verify a dataset-plus-config update preserves compatible inherited query state, drops only incompatible query fields, retains dataset-independent presentation state, and writes the replacement dataset to both chart fields and params.datasource.
  7. Verify explicit empty grouping on a dataset rebind does not cause unrelated state to be discarded.
  8. Verify filters that differ only by comparator remain distinct while generated temporal bindings are still deduplicated.

Automated validation performed:

  • 118 passed across test_update_chart.py and test_update_chart_preview.py
  • 1393 passed across tests/unit_tests/mcp_service/chart/
  • pre-commit run (all applicable hooks passed)
  • Post-merge focused pre-commit checks passed for all five changed Python files, including mypy, ruff, and pylint

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@codecov

codecov Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.60870% with 39 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.12%. Comparing base (f69023a) to head (6fb8ade).

Files with missing lines Patch % Lines
superset/mcp_service/chart/tool/update_chart.py 49.27% 26 Missing and 9 partials ⚠️
superset/mcp_service/chart/chart_utils.py 82.60% 3 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
hive 37.36% <9.78%> (-0.03%) ⬇️
mysql 56.92% <9.78%> (-0.05%) ⬇️
postgres 56.95% <9.78%> (-0.05%) ⬇️
presto ?
python 84.47% <57.60%> (+27.18%) ⬆️
sqlite 56.65% <9.78%> (-0.05%) ⬇️
unit 75.78% <57.60%> (?)

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 requested review from gabotorresruiz and removed request for Antonio-RiveroMartnez September 4, 2026 04:39
@aminghadersohi
aminghadersohi marked this pull request as draft September 4, 2026 04:58
@aminghadersohi
aminghadersohi force-pushed the mcp-update-chart-preserve-form-data branch from b47bd4a to 4a655cd Compare September 4, 2026 06:03
@pull-request-size pull-request-size Bot added size/L and removed size/M labels Sep 4, 2026
@aminghadersohi
aminghadersohi force-pushed the mcp-update-chart-preserve-form-data branch from 4a655cd to 93f4934 Compare September 4, 2026 06:33
@github-actions github-actions Bot removed the requires:rebase Requires rebasing on top of current master label Sep 4, 2026
@aminghadersohi
aminghadersohi marked this pull request as ready for review September 6, 2026 19:15
@bito-code-review

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

Copy link
Copy Markdown
Contributor

Code Review Agent Run #14e8c5

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 93f4934..22a7997
    • superset/mcp_service/chart/tool/update_chart.py
    • tests/unit_tests/mcp_service/chart/tool/test_update_chart.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 an incremental AI Review.

  • /review full - 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

@gabotorresruiz gabotorresruiz 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.

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.

@pull-request-size pull-request-size Bot added size/XL and removed size/L labels Sep 8, 2026
@bito-code-review

bito-code-review Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #82b639

Actionable Suggestions - 0
Additional Suggestions - 3
  • superset/mcp_service/chart/tool/update_chart.py - 2
    • Cleared fields treated as inherited · Line 329-340
      `_inherited_state_matches_dataset` treats a field the user explicitly cleared (e.g. `group_by=[]`) as inherited: `map_config_to_form_data` omits empty-valued keys, so `key not in new_form_data` is true and the stale `existing_form_data` value is validated. If incompatible, `_build_replacement_form_data` resets `existing_form_data={}`, dropping all other valid state (filters, metrics, column_config). Skip keys whose config field is in `parsed_config.model_fields_set`.
    • Over-broad state reset · Line 390-390
      Resetting `existing_form_data = {}` discards dataset-independent UI-only settings (`column_config`, `pivot_table_state`, `conditional_formatting`) that `merge_table_column_config` and `merge_interactive_pivot_ui_config` exist to preserve. When rebinding to a new dataset, only the query fields that fail `_inherited_state_matches_dataset` should be cleared, not the whole form data. Consider popping just the invalid query keys.
  • superset/mcp_service/chart/chart_utils.py - 1
    • Dedup drops distinct filters · Line 1863-1871
      The `is_same_filter` dedup compares clause, expressionType, subject, and operator but omits `comparator`, which holds the filter value for SIMPLE filters. Two valid filters on the same column with different comparators (e.g. `ds > 2020` vs `ds > 2021`) are treated as identical and one is silently dropped from `merged_filters`. Include `comparator` in the comparison.
Review Details
  • Files reviewed - 4 · Commit Range: 22a7997..6a4de20
    • superset/mcp_service/chart/chart_utils.py
    • 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.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 an incremental AI Review.

  • /review full - 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

…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
@aminghadersohi

Copy link
Copy Markdown
Contributor Author

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.

aminghadersohi and others added 2 commits September 9, 2026 20:26
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]>
@aminghadersohi
aminghadersohi merged commit 74eb298 into master Sep 9, 2026
74 of 75 checks passed
@aminghadersohi
aminghadersohi deleted the mcp-update-chart-preserve-form-data branch September 9, 2026 21:43
@bito-code-review

Copy link
Copy Markdown
Contributor

Bito Automatic Review Skipped – PR Already Merged

Bito scheduled an automatic review for this pull request, but the review was skipped because this PR was merged before the review could be run.
No action is needed if you didn't intend to review it. To get a review, you can type /review in a comment and save it

if dataset_rebind:
return dict(new_form_data)
fields_set = config.model_fields_set
if "filters" not in fields_set:

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.

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

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.

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.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants