aminghadersohi commented on code in PR #39922:
URL: https://github.com/apache/superset/pull/39922#discussion_r3501655817
##########
superset/mcp_service/chart/tool/get_chart_info.py:
##########
@@ -170,6 +170,21 @@ def _apply_unsaved_state_override(result: ChartInfo,
form_data_key: str) -> None
# Update viz_type from cached form_data if present
if result.form_data and "viz_type" in result.form_data:
result.viz_type = result.form_data["viz_type"]
+ if result.viz_type:
+ try:
+ from superset.mcp_service.chart.registry import (
+ display_name_for_viz_type,
+ )
+
+ result.chart_type_display_name =
display_name_for_viz_type(
+ result.viz_type
+ )
+ except Exception as exc: # noqa: BLE001
+ logger.debug(
+ "Failed to resolve display name for viz_type=%r:
%s",
+ result.viz_type,
+ exc,
+ )
Review Comment:
Declining — display-name enrichment IS applied to all saved charts.
`serialize_chart_object` (schemas.py line 584) calls
`display_name_for_viz_type(_viz_type)` for every chart it serializes, and
`ModelGetInfoCore` passes `serializer=serialize_chart_object` for the
saved-chart lookup. The `_apply_unsaved_state_override` function additionally
refreshes it when unsaved state overrides the `viz_type`.
##########
superset/mcp_service/chart/plugins/table.py:
##########
@@ -0,0 +1,136 @@
+# 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 collections.abc import Mapping
+from typing import Any, ClassVar
+
+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: ClassVar[Mapping[str, str]] = {
+ "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]:
+ if not isinstance(config, TableChartConfig):
+ return []
+ refs: list[ColumnRef] = list(config.columns)
+ if config.filters:
+ for f in config.filters:
+ refs.append(ColumnRef(name=f.column))
+ return refs
Review Comment:
Acknowledged — `sort_by` validation gap is a known limitation already noted
in PR comments and branch tracking. Extending `extract_column_refs` to include
`sort_by` entries is a follow-up item scoped to a separate PR (it's non-trivial
because `sort_by` entries use a different shape than column refs).
--
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]