codeant-ai-for-open-source[bot] commented on code in PR #39922:
URL: https://github.com/apache/superset/pull/39922#discussion_r3482296633
##########
superset/mcp_service/chart/tool/update_chart.py:
##########
@@ -471,6 +471,24 @@ async def update_chart( # noqa: C901
# config is already a typed ChartConfig | None (validated by Pydantic)
parsed_config = request.config
+ # Normalize column case to match dataset canonical names
+ # (mirrors generate_chart pipeline layer 4)
+ chart_datasource_id = getattr(chart, "datasource_id", None)
+ if parsed_config is not None and chart_datasource_id is not None:
+ from superset.mcp_service.chart.validation.dataset_validator
import (
+ DatasetValidator,
+ NORMALIZATION_EXCEPTIONS,
+ )
+
+ try:
+ parsed_config = DatasetValidator.normalize_column_names(
+ parsed_config, chart_datasource_id
+ )
Review Comment:
**Suggestion:** Column normalization is using the chart's current datasource
ID even when the request is rebinding to a different `dataset_id`. This can
normalize names against the wrong schema, producing incorrect canonical names
(or leaving wrong casing) before form-data mapping/validation. Use the
effective target dataset (`request.dataset_id` when present, otherwise the
existing chart datasource) for normalization so rebind+config updates are
normalized against the dataset that will actually be used. [incorrect variable
usage]
<details>
<summary><b>Severity Level:</b> Critical 🚨</summary>
```mdx
- ❌ Rebind+config updates can fail with column-not-found errors.
- ⚠️ Preview URLs use mismatched column casing for target dataset.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Call the MCP `update_chart` tool
(`superset/mcp_service/chart/tool/update_chart.py:83`)
with an `UpdateChartRequest` whose `identifier` points to an existing chart
bound to
dataset A, and whose `config` references columns from dataset B plus
`dataset_id` set to
dataset B (`superset/mcp_service/chart/schemas.py:15-37`).
2. Inside `update_chart`, the chart is loaded via
`find_chart_by_identifier(request.identifier)`
(`superset/mcp_service/chart/tool/update_chart.py:75-79`) and
`parsed_config` is set from
`request.config` (`superset/mcp_service/chart/tool/update_chart.py:129-130`).
3. Column normalization then runs at
`superset/mcp_service/chart/tool/update_chart.py:132-136`, computing
`chart_datasource_id
= getattr(chart, "datasource_id", None)` and calling
`DatasetValidator.normalize_column_names(parsed_config, chart_datasource_id)`
(`superset/mcp_service/chart/tool/update_chart.py:132-136`), which fetches
dataset A's
schema (`DatasetValidator._get_dataset_context`,
`superset/mcp_service/chart/validation/dataset_validator.py:206-259`) and
rewrites column
names to that dataset's canonical casing (`_get_canonical_column_name`,
`superset/mcp_service/chart/validation/dataset_validator.py:52-84`).
4. Later in the same request, validation and preview use the target dataset
B by passing
`dataset_id=request.dataset_id` into `_validate_update_against_dataset`
(`superset/mcp_service/chart/tool/update_chart.py:206-221, 26-47, 59-24`) and
`_create_preview_url`
(`superset/mcp_service/chart/tool/update_chart.py:23-36, 43-71`), so
the compile check and cached form_data are evaluated against dataset B's
schema while the
column names were normalized against dataset A, causing column-not-found
validation errors
or compile failures whenever `dataset_id` differs from `chart.datasource_id`
on a
rebind+config update.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=518e2d0f1f574a7cb725664451c95bd0&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=518e2d0f1f574a7cb725664451c95bd0&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<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:** 476:486
**Comment:**
*Incorrect Variable Usage: Column normalization is using the chart's
current datasource ID even when the request is rebinding to a different
`dataset_id`. This can normalize names against the wrong schema, producing
incorrect canonical names (or leaving wrong casing) before form-data
mapping/validation. Use the effective target dataset (`request.dataset_id` when
present, otherwise the existing chart datasource) for normalization so
rebind+config updates are normalized against the dataset that will actually be
used.
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%2F39922&comment_hash=3da0dcb573df93871fdbd53b6fee62901b7434a23f922d827970061c66754357&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39922&comment_hash=3da0dcb573df93871fdbd53b6fee62901b7434a23f922d827970061c66754357&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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]