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


##########
superset/mcp_service/chart/plugin.py:
##########
@@ -0,0 +1,262 @@
+# 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.
+
+"""
+ChartTypePlugin protocol and BaseChartPlugin base class.
+
+Each chart type owns its pre-validation, column extraction, form_data mapping,
+and post-map validation in a single plugin class. This eliminates the previous
+pattern of 4 separate dispatch points (schema_validator.py, 
dataset_validator.py,
+chart_utils.py, pipeline.py) that had to be updated in sync whenever a new 
chart
+type was added.
+"""
+
+from __future__ import annotations
+
+from collections.abc import Mapping
+from typing import Any, ClassVar, Protocol, runtime_checkable
+
+from superset.mcp_service.chart.schemas import ColumnRef
+from superset.mcp_service.common.error_schemas import ChartGenerationError
+
+
+@runtime_checkable
+class ChartTypePlugin(Protocol):
+    """
+    Protocol that every chart-type plugin must satisfy.
+
+    Implementing all eight methods in a single class guarantees that adding a
+    new chart type requires only one new file — the plugin — rather than edits
+    across multiple separate files.

Review Comment:
   **Suggestion:** The protocol docstring says implementing “all eight methods” 
is required, but the protocol actually defines nine methods (including 
`schema_error_hint`). This mismatch will mislead plugin authors and can cause 
incomplete implementations when someone follows the documented count; update 
the docstring to match the real contract. [docstring mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Minor 🧹</summary>
   
   ```mdx
   - ⚠️ Misleads plugin authors on required protocol methods.
   - ⚠️ New plugins may omit schema_error_hint implementation.
   - ⚠️ Missing method may break schema error hint flow.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Open `superset/mcp_service/chart/plugin.py` and inspect the 
`ChartTypePlugin` docstring
   at lines 39-45; it claims that implementing "all eight methods" is required 
for a
   chart-type plugin.
   
   2. Scroll down in the same file and count the protocol methods actually 
defined (lines
   59-176): `pre_validate`, `extract_column_refs`, `to_form_data`, 
`post_map_validate`,
   `normalize_column_refs`, `get_runtime_warnings`, `generate_name`, 
`resolve_viz_type`, and
   `schema_error_hint` — nine methods in total.
   
   3. Follow the extension instructions in 
`superset/mcp_service/chart/plugins/__init__.py`
   lines 24-28, which tell developers to create
   `superset/mcp_service/chart/plugins/{chart_type}.py` and implement a class 
extending
   `BaseChartPlugin`, or logically a `ChartTypePlugin`-compatible class.
   
   4. If a developer instead implements a new plugin class conforming to the 
(misdocumented)
   "eight methods" and omits `schema_error_hint`, then when schema validation 
fails,
   `SchemaValidator._enhance_validation_error` in
   `superset/mcp_service/chart/validation/schema_validator.py` lines 214-220 
calls
   `plugin.schema_error_hint()` on the registry plugin; a plugin lacking this 
method will
   raise `AttributeError`, or at minimum never supply the intended 
chart-type-specific hint,
   because the documentation did not clearly state that `schema_error_hint` is 
part of the
   required method set.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=e4ebde00635340e98a181ba34a47ef00&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=e4ebde00635340e98a181ba34a47ef00&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/plugin.py
   **Line:** 42:44
   **Comment:**
        *Docstring Mismatch: The protocol docstring says implementing “all 
eight methods” is required, but the protocol actually defines nine methods 
(including `schema_error_hint`). This mismatch will mislead plugin authors and 
can cause incomplete implementations when someone follows the documented count; 
update the docstring to match the real contract.
   
   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=394a41fb115a745d1915fd98863e86bfe9a1771b4e7b0fde43718c77c1e7423c&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39922&comment_hash=394a41fb115a745d1915fd98863e86bfe9a1771b4e7b0fde43718c77c1e7423c&reaction=dislike'>👎</a>



##########
superset/mcp_service/chart/plugins/table.py:
##########
@@ -0,0 +1,135 @@
+# 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.
+
+"""Table chart type plugin."""
+
+from __future__ import annotations
+
+from typing import Any
+
+from superset.mcp_service.chart.chart_utils import (
+    _summarize_filters,
+    _table_chart_what,
+    map_table_config,
+)
+from superset.mcp_service.chart.plugin import BaseChartPlugin
+from superset.mcp_service.chart.schemas import ColumnRef, TableChartConfig
+from superset.mcp_service.chart.validation.dataset_validator import 
DatasetValidator
+from superset.mcp_service.common.error_schemas import ChartGenerationError
+
+
+class TableChartPlugin(BaseChartPlugin):
+    """Plugin for table chart type."""
+
+    chart_type = "table"
+    display_name = "Table"
+    native_viz_types = {
+        "table": "Table",
+        "ag-grid-table": "Interactive Table",
+    }
+
+    def pre_validate(
+        self,
+        config: dict[str, Any],
+    ) -> ChartGenerationError | None:
+        columns = (
+            config.get("columns") or config.get("all_columns") or 
config.get("groupby")
+        )
+        if not columns:
+            return ChartGenerationError(
+                error_type="missing_columns",
+                message="Table chart missing required field: columns",
+                details=(
+                    "Table charts require a 'columns' array to specify which "
+                    "columns to display"
+                ),
+                suggestions=[
+                    "Add 'columns' field with array of column specifications",
+                    "Example: 'columns': [{'name': 'product'}, {'name': 
'sales', "
+                    "'aggregate': 'SUM'}]",
+                    "Each column can have optional 'aggregate' for metrics",
+                ],
+                error_code="MISSING_COLUMNS",
+            )
+
+        if not isinstance(columns, list):
+            return ChartGenerationError(
+                error_type="invalid_columns_format",
+                message="Columns must be a list",
+                details="The 'columns' field must be an array of column 
specifications",
+                suggestions=[
+                    "Ensure columns is an array: 'columns': [...]",
+                    "Each column should be an object with 'name' field",
+                ],
+                error_code="INVALID_COLUMNS_FORMAT",
+            )
+
+        return None
+
+    def extract_column_refs(self, config: Any) -> list[ColumnRef]:

Review Comment:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > Do not require docstrings for short, self-evident Python methods whose 
behavior is already clear from their names, type signatures, or surrounding 
protocol definitions; only flag docstrings when the purpose or contract is 
non-obvious.
   
   **Applied to:**
     - `**/*.py`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



-- 
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