codeant-ai-for-open-source[bot] commented on code in PR #39922:
URL: https://github.com/apache/superset/pull/39922#discussion_r3398659220


##########
superset/mcp_service/chart/plugins/pie.py:
##########
@@ -0,0 +1,137 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Pie chart type plugin."""
+
+from __future__ import annotations
+
+from typing import Any
+
+from superset.mcp_service.chart.chart_utils import (
+    _pie_chart_what,
+    _summarize_filters,
+    map_pie_config,
+)
+from superset.mcp_service.chart.plugin import BaseChartPlugin
+from superset.mcp_service.chart.schemas import ColumnRef, PieChartConfig
+from superset.mcp_service.chart.validation.dataset_validator import 
DatasetValidator
+from superset.mcp_service.common.error_schemas import ChartGenerationError
+
+
+class PieChartPlugin(BaseChartPlugin):
+    """Plugin for pie chart type."""
+
+    chart_type = "pie"
+    display_name = "Pie / Donut Chart"
+    native_viz_types = {
+        "pie": "Pie Chart",
+    }
+
+    def pre_validate(
+        self,
+        config: dict[str, Any],
+    ) -> ChartGenerationError | None:
+        missing_fields = []
+
+        if "dimension" not in config:
+            missing_fields.append("'dimension' (category column for slices)")

Review Comment:
   **Suggestion:** The pre-validation only accepts the canonical `dimension` 
key, but the schema explicitly supports `groupby` as an alias. Requests using 
`groupby` are valid for `PieChartConfig` yet will be rejected early as missing 
required fields, causing a contract mismatch between pre-validation and schema 
parsing. Accept both keys in pre-validation. [api mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Pie charts using groupby alias rejected as invalid.
   - ⚠️ generate_chart pipeline blocks otherwise schema-valid pie configs.
   - ⚠️ Pre-validation and PieChartConfig contract are inconsistent.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Create a chart generation request for the MCP `generate_chart` tool
   (`superset/mcp_service/chart/tool/generate_chart.py:220-57`) with 
`config.chart_type =
   "pie"`, `config.groupby = {...}` providing the slice dimension, and 
`config.metric =
   {...}` providing the metric; intentionally omit the `dimension` key and use 
`groupby`
   instead.
   
   2. The request enters `ValidationPipeline.validate_request_with_warnings()`
   (`superset/mcp_service/chart/validation/pipeline.py:60-80`), which first 
calls
   `SchemaValidator.validate_request(request_data)` for schema validation
   (`superset/mcp_service/chart/validation/schema_validator.py:39-61`).
   
   3. Inside `_pre_validate()` (`schema_validator.py:64-143`), the code 
extracts `config` and
   `chart_type="pie"`, then `_pre_validate_chart_type()` 
(`schema_validator.py:146-199`)
   looks up the `"pie"` plugin and calls `PieChartPlugin.pre_validate(config)`
   (`superset/mcp_service/chart/plugins/pie.py:44-73`) on the raw dict.
   
   4. Because `pre_validate` only checks `"dimension" not in config` at 
`pie.py:50-51` and
   ignores the supported alias `groupby` even though `PieChartConfig.dimension` 
is declared
   with `validation_alias=AliasChoices("dimension", "groupby")` 
(`schemas.py:287-292`), it
   appends `"'dimension' (category column for slices)"` to `missing_fields`, 
returns a
   `ChartGenerationError` with code `MISSING_PIE_FIELDS` (`pie.py:55-71`), and
   `SchemaValidator.validate_request` returns `is_valid=False`. As a result, 
`generate_chart`
   returns a validation error and the pie chart request using the valid 
`groupby` alias is
   rejected before Pydantic schema parsing could accept it.
   ```
   </details>
   
   [Fix in 
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=8f5188fea4a74d39aa558076a4c5cb80&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 | [Fix in VSCode 
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=8f5188fea4a74d39aa558076a4c5cb80&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/plugins/pie.py
   **Line:** 50:51
   **Comment:**
        *Api Mismatch: The pre-validation only accepts the canonical 
`dimension` key, but the schema explicitly supports `groupby` as an alias. 
Requests using `groupby` are valid for `PieChartConfig` yet will be rejected 
early as missing required fields, causing a contract mismatch between 
pre-validation and schema parsing. Accept both keys in pre-validation.
   
   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=040a0bc39d93529e6266d74fa717c75b5cd8f5769f8d4a8cefee3f33c91e89c8&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39922&comment_hash=040a0bc39d93529e6266d74fa717c75b5cd8f5769f8d4a8cefee3f33c91e89c8&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]

Reply via email to