You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "aminghadersohi (via GitHub)" <gi...@apache.org> on 2026/07/31 18:40:48 UTC
[PR] fix(mcp): preserve table chart state during updates [superset]
aminghadersohi opened a new pull request, #42655:
URL: https://github.com/apache/superset/pull/42655
### SUMMARY
Adds safe patch semantics for updating existing table charts through MCP and fixes stale-filter handling during previews.
- Adds `add_columns` to `update_chart`, allowing callers to append table dimensions or metrics without reconstructing or replacing the saved column list.
- Honors an explicit `filters: []` by removing saved ad hoc filters from preview form data.
- Treats Superset's inert `No filter` temporal placeholder as non-filtering during dataset-column validation.
- Clarifies validation guidance so it describes the accepted filter-clearing request exactly.
- Adds regression coverage for additive updates, parenthesized column names, explicit filter clearing, and inert stale filters.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Not applicable. This changes the MCP API and validation behavior without UI changes.
### TESTING INSTRUCTIONS
```bash
ruff check superset/mcp_service/chart/schemas.py superset/mcp_service/chart/tool/update_chart.py superset/mcp_service/chart/compile.py tests/unit_tests/mcp_service/chart/tool/test_update_chart.py tests/unit_tests/mcp_service/chart/test_compile.py
python -m pytest -q tests/unit_tests/mcp_service/chart/tool/test_update_chart.py tests/unit_tests/mcp_service/chart/test_compile.py
pre-commit run
```
The focused MCP suite passes 82 tests. The staged-file pre-commit gate passes. The all-files gate was also run; its failures are pre-existing repository-wide mypy errors and missing frontend dependencies, unrelated to these Python-only changes.
**Eval evidence:** Four focused regression scenarios are included in the 82 passing tests: additive metric preservation, parenthesized column names, explicit empty-filter replacement, and inert stale-filter validation.
**Cost & latency delta:** Adds 0 LLM calls and 0 external requests. The update path adds only in-memory list/dictionary merging and a linear scan of saved filters; no runtime benchmark was needed for this local operation.
### ADDITIONAL INFORMATION
**Blast radius:** Limited to MCP `update_chart` table updates and MCP chart filter validation. Existing full-config replacement behavior remains available.
**Risk and rollback:** Low. The new request field is additive, and reverting this commit restores the prior behavior. Non-table charts reject `add_columns` with an actionable validation error.
**Review guidance:** Focus on preservation of existing `groupby`/`metrics`/`all_columns`, and the distinction between omitted filters (preserve) and explicit `filters: []` (clear).
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [x] Introduces new feature or API
- [ ] Removes existing feature or API
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): preserve table chart state during updates [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #42655:
URL: https://github.com/apache/superset/pull/42655#issuecomment-5273914751
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**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 <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): preserve table chart state during updates [superset]
Posted by "gabotorresruiz (via GitHub)" <gi...@apache.org>.
gabotorresruiz commented on code in PR #42655:
URL: https://github.com/apache/superset/pull/42655#discussion_r3768658210
##########
superset/mcp_service/chart/tool/update_chart.py:
##########
@@ -185,7 +302,16 @@ def _build_preview_form_data(
parsed_config, dataset_id=effective_dataset_id
)
new_form_data.pop("_mcp_warnings", None)
- merged = {**existing_form_data, **new_form_data}
+ # An explicit filters list, including [], replaces saved filters. An
+ # omitted filters field preserves them through the shallow merge.
Review Comment:
This block worries me a bit, or rather the comment does. It is accurate for the preview path, but the save path does not share it: `_build_update_payload` builds `params` from `new_form_data` alone, so an omitted `filters` field is not preserved there.
I ran both on this branch with a chart whose params had an adhoc filter plus `color_scheme` and `server_pagination`, updating with a config that omits `filters`. The preview keeps all three; the saved params come out as `all_columns, columns, include_time, order_desc, query_mode, row_limit, viz_type`.
Not something this PR introduces, and I understand `config` means full replacement. But preview and save disagreeing means the explore URL the caller reviews is not what a save produces. Can we scope the comment to the preview path, and maybe file a follow up for the divergence itself?
##########
superset/mcp_service/chart/tool/update_chart.py:
##########
@@ -95,6 +100,98 @@ def _wrapped_form_data_for_response(
return payload
+def _entry_key(entry: Any) -> str:
+ """Stable identity for a form_data column or metric entry.
+
+ Metric lists mix saved-metric names with adhoc metric dicts, so entries
+ are not reliably hashable. Serializing gives every shape a comparable
+ key without dropping the unhashable ones.
+ """
+ return json.dumps(entry, sort_keys=True, default=str)
+
+
+def _extend_without_duplicates(existing: list[Any], additions: Any) -> list[Any]:
+ """Append entries that are not already present, preserving order.
+
+ Column and metric order drives the rendered table layout, so appending
+ keeps first-occurrence position rather than rebuilding from a set.
+ """
+ merged = list(existing)
+ seen = {_entry_key(entry) for entry in merged}
+ for entry in additions:
+ key = _entry_key(entry)
+ if key in seen:
+ continue
+ seen.add(key)
+ merged.append(entry)
+ return merged
+
+
+def _append_table_columns(
+ existing_form_data: dict[str, Any],
+ columns: list[ColumnRef],
+) -> dict[str, Any] | GenerateChartResponse:
+ """Append table columns/metrics without replacing the saved column lists."""
+ if existing_form_data.get("viz_type") not in {"table", "ag-grid-table"}:
+ return _validation_error_response(
+ message="'add_columns' is only supported for table charts.",
+ details=(
+ "Use 'config' to replace the full configuration of a non-table chart."
+ ),
+ )
+
+ merged = dict(existing_form_data)
+ metric_columns = [column for column in columns if column.is_metric]
+ dimension_columns = [column for column in columns if not column.is_metric]
+ query_mode = existing_form_data.get("query_mode")
+ if query_mode == "raw":
Review Comment:
Not a blocker, more cheap insurance. This keys on the literal `query_mode == "raw"`, but Superset treats a table with no `query_mode` and a non-empty `all_columns` as raw. That fallback is in `plugin-chart-table/src/buildQuery.ts` (`getQueryMode`) and in the backend as `is_raw_query_mode()` in `superset/common/form_data_query_context.py`.
I checked it on this branch with params `{"viz_type": "table", "all_columns": ["employer", "state"]}`. Adding `{"name": "amount", "aggregate": "SUM"}` returns a payload with the metric appended, no error; the same chart with `query_mode: "raw"` present does return "Cannot add metrics to a table in raw query mode." Dimensions have the mirror problem: they land in `groupby` while `all_columns` keeps the old list.
`is_raw_query_mode(existing_form_data)` here would cover both. Fair warning: every table chart in `superset/examples` that has `all_columns` also sets `query_mode`, so this may be theoretical today.
##########
tests/unit_tests/mcp_service/chart/tool/test_update_chart.py:
##########
@@ -638,6 +644,258 @@ def test_config_update_keeps_existing_name(self):
# query_context must be cleared so get_chart_data uses updated params
assert result["query_context"] is None
+ def test_add_columns_preserves_existing_columns_and_metrics(self):
+ """An additive update does not require reconstructing the table."""
+ request = UpdateChartRequest(
+ identifier=1,
+ add_columns=[
+ ColumnRef(
+ name="go_live_date", aggregate="MIN", label="Earliest Go Live Date"
+ )
+ ],
+ )
+ chart = Mock()
+ chart.slice_name = "Existing"
+ chart.params = json.dumps(
+ {
+ "viz_type": "ag-grid-table",
+ "query_mode": "aggregate",
+ "groupby": ["employer"],
+ "metrics": ["count"],
+ }
+ )
+
+ result = _build_update_payload(request, chart)
+
+ assert isinstance(result, dict)
+ params = json.loads(result["params"])
+ assert params["groupby"] == ["employer"]
+ assert params["metrics"][0] == "count"
+ assert params["metrics"][1]["label"] == "Earliest Go Live Date"
+ assert params["metrics"][1]["aggregate"] == "MIN"
+
+ def test_add_columns_rebinds_requested_dataset(self):
+ """Additive saves validate and persist against the same dataset."""
+ request = UpdateChartRequest(
+ identifier=1,
+ dataset_id=22,
+ add_columns=[ColumnRef(name="region")],
+ )
+ chart = Mock(
+ slice_name="Existing",
+ params=json.dumps(
+ {
+ "viz_type": "table",
+ "query_mode": "aggregate",
+ "groupby": ["employer"],
+ "metrics": [],
+ }
+ ),
+ )
+
+ result = _build_update_payload(request, chart)
+
+ assert isinstance(result, dict)
+ assert result["datasource_id"] == 22
Review Comment:
This one passes on master as well. I copied both changed test files onto `56573fa` and ran them: 14 of the new tests fail there, and this is not one of them. Pre-fix, pydantic just ignores the unknown `add_columns` field and the dataset only branch returns the same `datasource_id` and `datasource_type` you assert on.
An assert on `params` too, `groupby == ["employer", "region"]` and `slice_name` still "Existing", would make it pin the additive rebind rather than the plain one.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): preserve table chart state during updates [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #42655:
URL: https://github.com/apache/superset/pull/42655#issuecomment-5188773131
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**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 <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): preserve table chart state during updates [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #42655:
URL: https://github.com/apache/superset/pull/42655#issuecomment-5203163446
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**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 <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): preserve table chart state during updates [superset]
Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on PR #42655:
URL: https://github.com/apache/superset/pull/42655#issuecomment-5272966264
Rebased onto latest master; all required checks are green, and the experimental Playwright failures matched the repo-wide embedded-dashboard flake seen on other open PRs (both experimental jobs are green after the rebase).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): preserve table chart state during updates [superset]
Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on code in PR #42655:
URL: https://github.com/apache/superset/pull/42655#discussion_r3717945815
##########
superset/mcp_service/chart/schemas.py:
##########
@@ -2379,6 +2387,19 @@ class UpdateChartRequest(ChartRequestNormalizerMixin, QueryCacheControl):
),
)
+ @model_validator(mode="after")
+ def validate_column_patch(self) -> "UpdateChartRequest":
+ """Keep full-config replacement and additive table updates unambiguous."""
+ if self.config is not None and self.add_columns is not None:
+ raise ValueError(
+ "Use either 'config' for a full visualization replacement or "
+ "'add_columns' to append table columns while preserving the existing "
+ "configuration, not both."
+ )
Review Comment:
Valid — both branches were untested. Added in `79f2704`:
```python
class TestUpdateChartRequestColumnPatchValidation:
def test_config_and_add_columns_together_rejected(self) # "not both"
def test_empty_add_columns_rejected(self) # "at least one column"
def test_add_columns_alone_accepted(self) # the valid shape
```
Writing these paid for itself: the dimension-only case they exercise led me to a real bug where appending a plain column to an aggregate table silently dropped it. Fixed in the same commit — see the PR comment.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): preserve table chart state during updates [superset]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #42655:
URL: https://github.com/apache/superset/pull/42655#issuecomment-5146463087
## [Codecov](https://app.codecov.io/gh/apache/superset/pull/42655?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `11.66667%` with `53 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 64.61%. Comparing base ([`035eaa8`](https://app.codecov.io/gh/apache/superset/commit/035eaa8b80c8b168d7e21cc2be57d81cb9e66973?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`edde2ec`](https://app.codecov.io/gh/apache/superset/commit/edde2ec9671e4b8fb4eacd58190021eae0063e45?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
| [Files with missing lines](https://app.codecov.io/gh/apache/superset/pull/42655?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [superset/mcp\_service/chart/tool/update\_chart.py](https://app.codecov.io/gh/apache/superset/pull/42655?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fchart%2Ftool%2Fupdate_chart.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2UvY2hhcnQvdG9vbC91cGRhdGVfY2hhcnQucHk=) | 4.34% | [44 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/42655?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [superset/mcp\_service/chart/schemas.py](https://app.codecov.io/gh/apache/superset/pull/42655?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fchart%2Fschemas.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2UvY2hhcnQvc2NoZW1hcy5weQ==) | 37.50% | [5 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/42655?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [superset/mcp\_service/chart/compile.py](https://app.codecov.io/gh/apache/superset/pull/42655?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fchart%2Fcompile.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2UvY2hhcnQvY29tcGlsZS5weQ==) | 33.33% | [4 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/42655?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #42655 +/- ##
==========================================
- Coverage 65.44% 64.61% -0.84%
==========================================
Files 2810 2810
Lines 159366 159418 +52
Branches 36374 36384 +10
==========================================
- Hits 104302 103007 -1295
- Misses 53022 54376 +1354
+ Partials 2042 2035 -7
```
| [Flag](https://app.codecov.io/gh/apache/superset/pull/42655/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [hive](https://app.codecov.io/gh/apache/superset/pull/42655/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `38.07% <11.66%> (-0.02%)` | :arrow_down: |
| [mysql](https://app.codecov.io/gh/apache/superset/pull/42655/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [postgres](https://app.codecov.io/gh/apache/superset/pull/42655/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [presto](https://app.codecov.io/gh/apache/superset/pull/42655/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `39.96% <11.66%> (-0.02%)` | :arrow_down: |
| [python](https://app.codecov.io/gh/apache/superset/pull/42655/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `57.60% <11.66%> (-1.66%)` | :arrow_down: |
| [sqlite](https://app.codecov.io/gh/apache/superset/pull/42655/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `57.46% <11.66%> (-0.03%)` | :arrow_down: |
| [unit](https://app.codecov.io/gh/apache/superset/pull/42655/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/superset/pull/42655?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): preserve table chart state during updates [superset]
Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on code in PR #42655:
URL: https://github.com/apache/superset/pull/42655#discussion_r3717944980
##########
superset/mcp_service/chart/schemas.py:
##########
@@ -2347,6 +2347,14 @@ class UpdateChartRequest(ChartRequestNormalizerMixin, QueryCacheControl):
None,
description="Chart configuration. Optional; omit to only update chart_name.",
)
+ add_columns: List[ColumnRef] | None = Field(
+ None,
+ description=(
+ "Table columns or metrics to append while preserving every existing "
+ "column and metric. Use this instead of config.columns when adding "
+ "columns to an existing table chart."
+ ),
+ )
Review Comment:
Partly. The `add_columns` field itself is covered — `test_update_chart.py` has `test_add_columns_preserves_existing_columns_and_metrics`, `test_add_columns_rebinds_requested_dataset`, and a parametrized `test_add_metric_to_raw_table_returns_actionable_error`. They live next to the other `_build_update_payload` tests rather than in `test_chart_schemas.py`, which is why the search missed them.
The validator was a real gap though, so I've added `TestUpdateChartRequestColumnPatchValidation` covering both error branches and the valid additive shape (see the reply on the `validate_column_patch` thread).
Writing the coverage you asked for also turned up an actual bug, so thanks — details in the other thread and in the PR comment.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): preserve table chart state during updates [superset]
Posted by "netlify[bot] (via GitHub)" <gi...@apache.org>.
netlify[bot] commented on PR #42655:
URL: https://github.com/apache/superset/pull/42655#issuecomment-5183844105
### <span aria-hidden="true">✅</span> Deploy Preview for *superset-docs-preview* ready!
| Name | Link |
|:-:|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | 00a6493012d665ba65f3c52e9beb3cbc5bad9a32 |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/projects/superset-docs-preview/deploys/6a724154eb563c000873f588 |
|<span aria-hidden="true">😎</span> Deploy Preview | [https://deploy-preview-42655--superset-docs-preview.netlify.app](https://deploy-preview-42655--superset-docs-preview.netlify.app) |
|<span aria-hidden="true">📱</span> Preview on mobile | <details><summary> Toggle QR Code... </summary><br /><br /><br /><br />_Use your smartphone camera to open QR code link._</details> |
|<span aria-hidden="true">🤖</span> Make changes | [Run an agent on this branch](https://app.netlify.com/projects/superset-docs-preview/agent-runs#Dco7DoAgDADQu3S2Cah84g08RikYB9AGcTDGu8v2hveC1LNIgwVggFDp4L37YtTa2NFhYcFbIrWEjUJOyDvVdvUck-TzWWPvltw4azOnYOzESinvps14D98P) |
---
<!-- [superset-docs-preview Preview](https://deploy-preview-42655--superset-docs-preview.netlify.app) -->
_To edit notification comments on pull requests, go to your [Netlify project configuration](https://app.netlify.com/projects/superset-docs-preview/configuration/notifications#deploy-notifications)._
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): preserve table chart state during updates [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on code in PR #42655:
URL: https://github.com/apache/superset/pull/42655#discussion_r3717945496
##########
superset/mcp_service/chart/schemas.py:
##########
@@ -2347,6 +2347,14 @@ class UpdateChartRequest(ChartRequestNormalizerMixin, QueryCacheControl):
None,
description="Chart configuration. Optional; omit to only update chart_name.",
)
+ add_columns: List[ColumnRef] | None = Field(
+ None,
+ description=(
+ "Table columns or metrics to append while preserving every existing "
+ "column and metric. Use this instead of config.columns when adding "
+ "columns to an existing table chart."
+ ),
+ )
Review Comment:
<!-- Bito Reply -->
It is good to hear that the coverage gaps have been addressed and that the additional testing led to the discovery of a bug. The addition of `TestUpdateChartRequestColumnPatchValidation` to cover both error branches and the valid additive shape is an appropriate way to resolve the concern regarding missing test coverage for the new field.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): preserve table chart state during updates [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on code in PR #42655:
URL: https://github.com/apache/superset/pull/42655#discussion_r3717626752
##########
superset/mcp_service/chart/schemas.py:
##########
@@ -2347,6 +2347,14 @@ class UpdateChartRequest(ChartRequestNormalizerMixin, QueryCacheControl):
None,
description="Chart configuration. Optional; omit to only update chart_name.",
)
+ add_columns: List[ColumnRef] | None = Field(
+ None,
+ description=(
+ "Table columns or metrics to append while preserving every existing "
+ "column and metric. Use this instead of config.columns when adding "
+ "columns to an existing table chart."
+ ),
+ )
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Missing test coverage for new field</b></div>
<div id="fix">
The new `add_columns` field (lines 2350-2357) has no corresponding unit tests in `test_chart_schemas.py`. Per the project's testing guidelines, every new MCP mutation tool schema field requires dedicated unit test coverage including request validation and schema serialization.
</div>
</div>
<small><i>Code Review Run #b295fd</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
##########
superset/mcp_service/chart/schemas.py:
##########
@@ -2379,6 +2387,19 @@ class UpdateChartRequest(ChartRequestNormalizerMixin, QueryCacheControl):
),
)
+ @model_validator(mode="after")
+ def validate_column_patch(self) -> "UpdateChartRequest":
+ """Keep full-config replacement and additive table updates unambiguous."""
+ if self.config is not None and self.add_columns is not None:
+ raise ValueError(
+ "Use either 'config' for a full visualization replacement or "
+ "'add_columns' to append table columns while preserving the existing "
+ "configuration, not both."
+ )
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Missing test for validator error branches</b></div>
<div id="fix">
The `validate_column_patch` validator (lines 2393-2401) that enforces mutual exclusivity of `config` and `add_columns` has no unit tests. Both its error branches — blocking co-provision and blocking empty list — are untested.
</div>
</div>
<small><i>Code Review Run #b295fd</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): preserve table chart state during updates [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #42655:
URL: https://github.com/apache/superset/pull/42655#issuecomment-5146318368
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): preserve table chart state during updates [superset]
Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on code in PR #42655:
URL: https://github.com/apache/superset/pull/42655#discussion_r3769970125
##########
superset/mcp_service/chart/tool/update_chart.py:
##########
@@ -95,6 +100,98 @@ def _wrapped_form_data_for_response(
return payload
+def _entry_key(entry: Any) -> str:
+ """Stable identity for a form_data column or metric entry.
+
+ Metric lists mix saved-metric names with adhoc metric dicts, so entries
+ are not reliably hashable. Serializing gives every shape a comparable
+ key without dropping the unhashable ones.
+ """
+ return json.dumps(entry, sort_keys=True, default=str)
+
+
+def _extend_without_duplicates(existing: list[Any], additions: Any) -> list[Any]:
+ """Append entries that are not already present, preserving order.
+
+ Column and metric order drives the rendered table layout, so appending
+ keeps first-occurrence position rather than rebuilding from a set.
+ """
+ merged = list(existing)
+ seen = {_entry_key(entry) for entry in merged}
+ for entry in additions:
+ key = _entry_key(entry)
+ if key in seen:
+ continue
+ seen.add(key)
+ merged.append(entry)
+ return merged
+
+
+def _append_table_columns(
+ existing_form_data: dict[str, Any],
+ columns: list[ColumnRef],
+) -> dict[str, Any] | GenerateChartResponse:
+ """Append table columns/metrics without replacing the saved column lists."""
+ if existing_form_data.get("viz_type") not in {"table", "ag-grid-table"}:
+ return _validation_error_response(
+ message="'add_columns' is only supported for table charts.",
+ details=(
+ "Use 'config' to replace the full configuration of a non-table chart."
+ ),
+ )
+
+ merged = dict(existing_form_data)
+ metric_columns = [column for column in columns if column.is_metric]
+ dimension_columns = [column for column in columns if not column.is_metric]
+ query_mode = existing_form_data.get("query_mode")
+ if query_mode == "raw":
+ if metric_columns:
+ return _validation_error_response(
+ message="Cannot add metrics to a table in raw query mode.",
+ details=(
+ "Raw tables accept only unaggregated columns in 'add_columns'. "
+ "Use 'config' with query_mode='aggregate' and the complete table "
+ "configuration to convert the chart before adding metrics."
+ ),
+ )
+ merged["all_columns"] = _extend_without_duplicates(
+ list(existing_form_data.get("all_columns") or []),
+ (column.name for column in columns if column.name is not None),
+ )
+ return merged
Review Comment:
Thanks for flagging this. As noted in the review summary, Superset unions `all_columns` and legacy `columns` in the raw query path, and `columns_from_form_data` also uses the populated `all_columns` representation, so existing columns are not dropped. No code change is needed for this thread.
##########
superset/mcp_service/chart/tool/update_chart.py:
##########
@@ -185,7 +302,16 @@ def _build_preview_form_data(
parsed_config, dataset_id=effective_dataset_id
)
new_form_data.pop("_mcp_warnings", None)
- merged = {**existing_form_data, **new_form_data}
+ # An explicit filters list, including [], replaces saved filters. An
+ # omitted filters field preserves them through the shallow merge.
Review Comment:
Addressed in 849ca9132d. I scoped the comment explicitly to preview behavior so it no longer implies that the save path preserves omitted filters. The preview/save divergence remains unchanged and can be handled separately.
##########
superset/mcp_service/chart/tool/update_chart.py:
##########
@@ -95,6 +100,98 @@ def _wrapped_form_data_for_response(
return payload
+def _entry_key(entry: Any) -> str:
+ """Stable identity for a form_data column or metric entry.
+
+ Metric lists mix saved-metric names with adhoc metric dicts, so entries
+ are not reliably hashable. Serializing gives every shape a comparable
+ key without dropping the unhashable ones.
+ """
+ return json.dumps(entry, sort_keys=True, default=str)
+
+
+def _extend_without_duplicates(existing: list[Any], additions: Any) -> list[Any]:
+ """Append entries that are not already present, preserving order.
+
+ Column and metric order drives the rendered table layout, so appending
+ keeps first-occurrence position rather than rebuilding from a set.
+ """
+ merged = list(existing)
+ seen = {_entry_key(entry) for entry in merged}
+ for entry in additions:
+ key = _entry_key(entry)
+ if key in seen:
+ continue
+ seen.add(key)
+ merged.append(entry)
+ return merged
+
+
+def _append_table_columns(
+ existing_form_data: dict[str, Any],
+ columns: list[ColumnRef],
+) -> dict[str, Any] | GenerateChartResponse:
+ """Append table columns/metrics without replacing the saved column lists."""
+ if existing_form_data.get("viz_type") not in {"table", "ag-grid-table"}:
+ return _validation_error_response(
+ message="'add_columns' is only supported for table charts.",
+ details=(
+ "Use 'config' to replace the full configuration of a non-table chart."
+ ),
+ )
+
+ merged = dict(existing_form_data)
+ metric_columns = [column for column in columns if column.is_metric]
+ dimension_columns = [column for column in columns if not column.is_metric]
+ query_mode = existing_form_data.get("query_mode")
+ if query_mode == "raw":
Review Comment:
Addressed in 849ca9132d. `_append_table_columns` now uses the shared backend `is_raw_query_mode(existing_form_data)` helper, with regression coverage for an implicit raw table that has `all_columns` but no `query_mode`.
##########
tests/unit_tests/mcp_service/chart/tool/test_update_chart.py:
##########
@@ -638,6 +644,258 @@ def test_config_update_keeps_existing_name(self):
# query_context must be cleared so get_chart_data uses updated params
assert result["query_context"] is None
+ def test_add_columns_preserves_existing_columns_and_metrics(self):
+ """An additive update does not require reconstructing the table."""
+ request = UpdateChartRequest(
+ identifier=1,
+ add_columns=[
+ ColumnRef(
+ name="go_live_date", aggregate="MIN", label="Earliest Go Live Date"
+ )
+ ],
+ )
+ chart = Mock()
+ chart.slice_name = "Existing"
+ chart.params = json.dumps(
+ {
+ "viz_type": "ag-grid-table",
+ "query_mode": "aggregate",
+ "groupby": ["employer"],
+ "metrics": ["count"],
+ }
+ )
+
+ result = _build_update_payload(request, chart)
+
+ assert isinstance(result, dict)
+ params = json.loads(result["params"])
+ assert params["groupby"] == ["employer"]
+ assert params["metrics"][0] == "count"
+ assert params["metrics"][1]["label"] == "Earliest Go Live Date"
+ assert params["metrics"][1]["aggregate"] == "MIN"
+
+ def test_add_columns_rebinds_requested_dataset(self):
+ """Additive saves validate and persist against the same dataset."""
+ request = UpdateChartRequest(
+ identifier=1,
+ dataset_id=22,
+ add_columns=[ColumnRef(name="region")],
+ )
+ chart = Mock(
+ slice_name="Existing",
+ params=json.dumps(
+ {
+ "viz_type": "table",
+ "query_mode": "aggregate",
+ "groupby": ["employer"],
+ "metrics": [],
+ }
+ ),
+ )
+
+ result = _build_update_payload(request, chart)
+
+ assert isinstance(result, dict)
+ assert result["datasource_id"] == 22
Review Comment:
Addressed in 849ca9132d. The test now asserts the preserved slice name and the additive params result (`groupby == ["employer", "region"]`), so it fails before the additive rebind behavior exists.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): preserve table chart state during updates [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on code in PR #42655:
URL: https://github.com/apache/superset/pull/42655#discussion_r3717946245
##########
superset/mcp_service/chart/schemas.py:
##########
@@ -2379,6 +2387,19 @@ class UpdateChartRequest(ChartRequestNormalizerMixin, QueryCacheControl):
),
)
+ @model_validator(mode="after")
+ def validate_column_patch(self) -> "UpdateChartRequest":
+ """Keep full-config replacement and additive table updates unambiguous."""
+ if self.config is not None and self.add_columns is not None:
+ raise ValueError(
+ "Use either 'config' for a full visualization replacement or "
+ "'add_columns' to append table columns while preserving the existing "
+ "configuration, not both."
+ )
Review Comment:
<!-- Bito Reply -->
The suggestion to add unit tests for the validator error branches is appropriate and improves the code's robustness. Implementing these tests ensures that the mutual exclusivity of 'config' and 'add_columns' is correctly enforced and helps prevent regressions, as demonstrated by the bug you identified and fixed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): preserve table chart state during updates [superset]
Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #42655:
URL: https://github.com/apache/superset/pull/42655#discussion_r3763581995
##########
superset/mcp_service/chart/tool/update_chart.py:
##########
@@ -95,6 +100,98 @@ def _wrapped_form_data_for_response(
return payload
+def _entry_key(entry: Any) -> str:
+ """Stable identity for a form_data column or metric entry.
+
+ Metric lists mix saved-metric names with adhoc metric dicts, so entries
+ are not reliably hashable. Serializing gives every shape a comparable
+ key without dropping the unhashable ones.
+ """
+ return json.dumps(entry, sort_keys=True, default=str)
+
+
+def _extend_without_duplicates(existing: list[Any], additions: Any) -> list[Any]:
+ """Append entries that are not already present, preserving order.
+
+ Column and metric order drives the rendered table layout, so appending
+ keeps first-occurrence position rather than rebuilding from a set.
+ """
+ merged = list(existing)
+ seen = {_entry_key(entry) for entry in merged}
+ for entry in additions:
+ key = _entry_key(entry)
+ if key in seen:
+ continue
+ seen.add(key)
+ merged.append(entry)
+ return merged
+
+
+def _append_table_columns(
+ existing_form_data: dict[str, Any],
+ columns: list[ColumnRef],
+) -> dict[str, Any] | GenerateChartResponse:
+ """Append table columns/metrics without replacing the saved column lists."""
+ if existing_form_data.get("viz_type") not in {"table", "ag-grid-table"}:
+ return _validation_error_response(
+ message="'add_columns' is only supported for table charts.",
+ details=(
+ "Use 'config' to replace the full configuration of a non-table chart."
+ ),
+ )
+
+ merged = dict(existing_form_data)
+ metric_columns = [column for column in columns if column.is_metric]
+ dimension_columns = [column for column in columns if not column.is_metric]
+ query_mode = existing_form_data.get("query_mode")
+ if query_mode == "raw":
+ if metric_columns:
+ return _validation_error_response(
+ message="Cannot add metrics to a table in raw query mode.",
+ details=(
+ "Raw tables accept only unaggregated columns in 'add_columns'. "
+ "Use 'config' with query_mode='aggregate' and the complete table "
+ "configuration to convert the chart before adding metrics."
+ ),
+ )
+ merged["all_columns"] = _extend_without_duplicates(
+ list(existing_form_data.get("all_columns") or []),
+ (column.name for column in columns if column.name is not None),
+ )
+ return merged
Review Comment:
**Suggestion:** Raw-mode patches update only `all_columns`, leaving the existing `columns` representation untouched. For legacy raw charts that have `query_mode='raw'` and `columns` but no `all_columns`, this creates a new `all_columns` containing only the additions; query construction then prefers that new list and silently drops every previously selected column. Keep both raw column representations synchronized, or preserve the existing list when initializing `all_columns`. [api mismatch]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Additive updates can remove existing fields from legacy raw table queries.
- ⚠️ Saved table results and preview output no longer match the original chart.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=73ec0372d59947e29f112bd358c0bee0&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=73ec0372d59947e29f112bd358c0bee0&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/mcp_service/chart/tool/update_chart.py
**Line:** 147:161
**Comment:**
*Api Mismatch: Raw-mode patches update only `all_columns`, leaving the existing `columns` representation untouched. For legacy raw charts that have `query_mode='raw'` and `columns` but no `all_columns`, this creates a new `all_columns` containing only the additions; query construction then prefers that new list and silently drops every previously selected column. Keep both raw column representations synchronized, or preserve the existing list when initializing `all_columns`.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42655&comment_hash=55f5a14c7b52a3e1c9e829dc74698e8085f5430202caf58102949aedbbed7560&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42655&comment_hash=55f5a14c7b52a3e1c9e829dc74698e8085f5430202caf58102949aedbbed7560&reaction=dislike'>👎</a>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): preserve table chart state during updates [superset]
Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on PR #42655:
URL: https://github.com/apache/superset/pull/42655#issuecomment-5201367604
Thanks — looked at this one, but leaving the code as-is. The premise doesn't match what the helper does:
> serializes the entire entry on every `in`-set check ... O(n) overhead per lookup
Each entry is serialized **exactly once**, not per lookup. The set is built once up front, and each addition is keyed once; the `in` check is then an O(1) hash lookup on an already-computed string:
```python
merged = list(existing)
seen = {_entry_key(entry) for entry in merged} # once per existing entry
for entry in additions:
key = _entry_key(entry) # once per addition
if key in seen: # O(1), no serialization
continue
```
So it's O(n+m) serializations total, not O(n) per lookup. Measured at 2× the size cited (200 entries — 100 saved-metric names plus 100 adhoc dicts):
```
200 existing entries, 2000 calls -> 343.0 us per call
```
0.3 ms, once per `update_chart` call, alongside a dataset read, chart compilation, and a network round-trip. Caching or a structural hash would add state and complexity for no measurable gain, so I'd rather keep the straightforward version.
Worth noting the serialization isn't incidental — it's what makes the dedup correct. `metrics` mixes saved-metric names with adhoc dicts, so the obvious `set()` raises `TypeError: unhashable type: 'dict'`, and it would also lose the ordering that drives table column layout.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): preserve table chart state during updates [superset]
Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi merged PR #42655:
URL: https://github.com/apache/superset/pull/42655
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): preserve table chart state during updates [superset]
Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on PR #42655:
URL: https://github.com/apache/superset/pull/42655#issuecomment-5187555170
Thanks @bito-code-review — worked through all five suggestions. All are addressed in `79f2704`, and chasing the dedup one uncovered a genuine bug in this PR.
### The bug the review led to
`_append_table_columns()` built its patch with `map_config_to_form_data(TableChartConfig(columns=...))`, which **infers `query_mode` from the columns it's handed**:
| appended columns | inferred mode | `groupby` |
|---|---|---|
| plain only | `raw` | `None` |
| metric only | `aggregate` | `None` |
| mixed | `aggregate` | `['region']` |
So a dimension-only append compiled to a *raw* patch, `patch.get("groupby")` was `None`, and `.extend(... or [])` appended nothing — **adding a plain column to an aggregate table silently did nothing.** Confirmed against the unmodified branch:
```
groupby -> ['employer'] # expected ['employer', 'region']
```
Existing tests missed it because they either appended a metric (`aggregate="MIN"`) or asserted only on `datasource_id`. Columns are now routed by `ColumnRef.is_metric`, so dimensions reach `groupby` and metrics reach `metrics` regardless of the mix, and the chart is never flipped out of aggregate mode.
### Suggestions 1 & 2 — test coverage
`add_columns` was already covered behaviorally in `test_update_chart.py` (not `test_chart_schemas.py`, hence the miss). The **validator was genuinely untested** — both error branches now are. Replied on both threads.
### Suggestions 3 & 4 — deduplication
Agreed on the substance, with one correction: the proposed `set()` approach doesn't work here.
```python
>>> set(['count', {'label': 'Earliest Go Live Date', 'aggregate': 'MIN'}])
TypeError: unhashable type: 'dict'
```
`metrics` mixes saved-metric names with adhoc metric **dicts**, so a set raises — and it would also discard the ordering that drives table column layout. Dedup is instead keyed on a stable serialization and preserves first-occurrence order, applied to `all_columns`, `groupby`, and `metrics`. Re-adding an existing column is now a no-op rather than a silent duplicate.
### Suggestion 5 — docs
Added an example combining `chart_name` with `add_columns`, noting that repeating an existing column is safe.
### Verification
`tests/unit_tests/mcp_service/` — **3283 passed**; `chart/` — **1184 passed**. Ruff format + check clean on the pinned 0.9.7. Six new tests, including regression coverage for the dropped-column bug.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): preserve table chart state during updates [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #42655:
URL: https://github.com/apache/superset/pull/42655#issuecomment-5186948933
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**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 <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): preserve table chart state during updates [superset]
Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on PR #42655:
URL: https://github.com/apache/superset/pull/42655#issuecomment-5272262230
Addressed the latest reviewer feedback in `849ca9132d`:
- use the shared `is_raw_query_mode()` semantics for tables with omitted `query_mode`, plus regression coverage
- scope the filter-preservation comment to the preview path
- strengthen the additive dataset-rebind test to assert preserved name and appended `groupby`
- documented why the CodeAnt legacy raw-column concern does not reproduce in Superset’s union/dedup query path
Validation: staged-file `pre-commit run` passes (including mypy, Ruff, and pylint). The focused pytest suite is blocked in this checkout by the environment’s missing `sqlglot.dialects.singlestore` module.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): preserve table chart state during updates [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #42655:
URL: https://github.com/apache/superset/pull/42655#issuecomment-5285422066
**Bito Automatic Review Skipped – PR Already Merged**<br/><br/>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.<br/>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
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org