bito-code-review[bot] commented on code in PR #44746:
URL: https://github.com/apache/superset/pull/44746#discussion_r4119770169
##########
superset/mcp_service/chart/tool/update_chart.py:
##########
@@ -866,19 +867,26 @@ async def update_chart( # noqa: C901
# config is already a typed ChartConfig | None (validated by Pydantic)
try:
+ config_plugin = (
+ get_registry().get(request.config.chart_type)
+ if request.config is not None
+ else None
+ )
parsed_config = (
- resolve_treemap_update_config(
+ config_plugin.resolve_update_config(
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>CWE-470: Disabled plugin skips config completion</b></div>
<div id="fix">
`get_registry().get()` returns None for disabled plugins, but this is a
saved-chart update path: the `plugin_for_viz_type` contract (registry.py) says
saved charts must be updated with their plugin's contract even when creating
new charts is disabled. With `treemap_v2` in `MCP_DISABLED_CHART_PLUGINS`, a
partial `TreemapChartUpdateConfig` skips `resolve_update_config` role
completion, so updating an existing treemap fails validation. Sibling lookups
at lines 158, 591, 820 use `plugin_for_viz_type`.
([CWE-470](https://cwe.mitre.org/data/definitions/470.html))
</div>
</div>
<details>
<summary><b>Citations</b></summary>
<ul>
<li>
Rule Violated: <a
href="https://github.com/apache/superset/blob/8d95326/.cursor/rules/dev-standard.mdc#L119">dev-standard.mdc:119</a>
</li>
</ul>
</details>
<small><i>Code Review Run #d830d4</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/plugins/gantt.py:
##########
@@ -235,3 +243,66 @@ def schema_error_hint(self) -> ChartGenerationError | None:
],
error_code="GANTT_VALIDATION_ERROR",
)
+
+ def build_query_dicts(
+ self,
+ form_data: dict[str, Any],
+ *,
+ viz_type: str,
+ engine: str,
+ row_limit: int | None,
+ order_desc: bool | None,
+ ) -> list[dict[str, Any]] | None:
+ from superset.mcp_service.chart.chart_helpers import (
+ build_single_query_dict,
+ resolve_gantt_query_fields,
+ )
+
+ columns, metrics, orderby, series_columns = resolve_gantt_query_fields(
+ form_data
+ )
+ query = build_single_query_dict(
+ form_data, columns, metrics, row_limit=row_limit
+ )
+ query["orderby"] = orderby
+ query["series_columns"] = series_columns
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Uncaught ValueError</b></div>
<div id="fix">
`resolve_gantt_query_fields` raises `ValueError` on malformed form_data
(missing `start_time`/`end_time`/`y_axis`, oversized tooltip lists). This
propagates uncaught through `build_query_dicts_from_form_data` →
`build_query_context_from_form_data` into `get_chart_data`, where the generic
`except (... ValueError ...)` (get_chart_data.py:1104) turns it into a generic
`InternalError`/`DataError`. The base contract says `build_query_dicts` returns
`None` to fall back to the shared builder; consider catching and returning
`None` or a structured error.
</div>
</div>
<small><i>Code Review Run #d830d4</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/plugins/treemap.py:
##########
@@ -150,3 +162,110 @@ def schema_error_hint(self) -> ChartGenerationError |
None:
],
error_code="TREEMAP_VALIDATION_ERROR",
)
+
+ def resolve_query_fields(
+ self, form_data: Mapping[str, Any], viz_type: str
+ ) -> tuple[list[Any], list[Any]] | None:
+ # Treemap has exactly these roles; stale controls from another plugin
+ # must not override its singular metric or ordered hierarchy.
+ metric = form_data.get("metric")
+ hierarchy = form_data.get("groupby") or []
+ return ([metric] if metric else []), (
+ [hierarchy] if isinstance(hierarchy, str) else list(hierarchy)
+ )
+
+ def build_query_dicts(
+ self,
+ form_data: dict[str, Any],
+ *,
+ viz_type: str,
+ engine: str,
+ row_limit: int | None,
+ order_desc: bool | None,
+ ) -> list[dict[str, Any]] | None:
+ from superset.mcp_service.chart.chart_helpers import (
+ apply_treemap_query_fields,
+ build_single_query_dict,
+ )
+
+ metrics, hierarchy = cast(
+ tuple[list[Any], list[Any]],
+ self.resolve_query_fields(form_data, viz_type),
+ )
+ query = build_single_query_dict(
+ form_data,
+ hierarchy,
+ metrics,
+ row_limit=row_limit,
+ order_desc=order_desc,
+ )
+ apply_treemap_query_fields(
+ query,
+ form_data,
+ hierarchy,
+ row_limit if row_limit is not None else form_data.get("row_limit"),
+ )
+ return [query]
+
+ def normalize_query_result(self, result: Any, form_data: Mapping[str,
Any]) -> Any:
+ from superset.mcp_service.chart.query_result import (
+ normalize_treemap_query_result,
+ )
+
+ return normalize_treemap_query_result(result, form_data)
+
+ def compile_row_limit(self, form_data: Mapping[str, Any]) -> int:
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>CWE-20: Unguarded int() row limit</b></div>
<div id="fix">
`compile_row_limit` calls `int(form_data.get("row_limit") or 10)` unguarded,
while sibling `preview_row_limit` (same diff) catches
TypeError/ValueError/OverflowError for the same value. A non-numeric
`row_limit` in persisted chart params raises ValueError inside `_compile_chart`
(compile.py:116), yielding a cryptic CHART_COMPILE_FAILED instead of the
fallback; TypeError escapes compile.py:188's except tuple. Mirror the sibling's
guard. ([CWE-20](https://cwe.mitre.org/data/definitions/20.html))
</div>
</div>
<small><i>Code Review Run #d830d4</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: [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]