Copilot commented on code in PR #41597:
URL: https://github.com/apache/superset/pull/41597#discussion_r3546988737
##########
superset/mcp_service/dataset/schemas.py:
##########
@@ -370,26 +364,24 @@ def create(cls, error: str, error_type: str) ->
"DatasetError":
class GetDatasetInfoRequest(MetadataCacheControl):
"""Request schema for get_dataset_info with support for ID or UUID."""
+ model_config = ConfigDict(populate_by_name=True)
+
identifier: Annotated[
int | str,
- Field(description="Dataset identifier - can be numeric ID or UUID
string"),
+ Field(
+ description="Dataset identifier - can be numeric ID or UUID
string",
+ validation_alias=AliasChoices("identifier", "id", "dataset_id"),
+ ),
]
select_columns: Annotated[
Review Comment:
GetDatasetInfoRequest.select_columns still doesn't accept the common
'columns' key; without a validation_alias this input will be ignored and
defaults will be used (the same silent-drop behavior this PR is addressing).
Add an AliasChoices mapping for select_columns here as well.
##########
tests/unit_tests/mcp_service/dashboard/test_dashboard_schemas.py:
##########
@@ -904,3 +909,40 @@ def test_none_error_is_not_wrapped(self) -> None:
"""A null error stays null rather than being wrapped."""
resp = DuplicateDashboardResponse(dashboard_url="http://host/d/1/")
assert resp.error is None
+
+
+class TestRequestSchemaAliasChoices:
+ """Test that LLM-friendly field name variants are accepted on the
+ dashboard MCP tool request schemas, so callers sending 'id'/'dashboard_id'
+ instead of 'identifier' (or 'columns' instead of 'select_columns')
+ don't silently have the field dropped."""
+
+ def test_get_dashboard_info_identifier_id_alias(self) -> None:
+ req = GetDashboardInfoRequest.model_validate({"id": 42})
+ assert req.identifier == 42
+
+ def test_get_dashboard_info_identifier_dashboard_id_alias(self) -> None:
+ req = GetDashboardInfoRequest.model_validate({"dashboard_id": 42})
+ assert req.identifier == 42
+
+ def test_get_dashboard_info_identifier_still_works(self) -> None:
+ req = GetDashboardInfoRequest.model_validate({"identifier": 42})
+ assert req.identifier == 42
+
+ def test_list_dashboards_select_columns_columns_alias(self) -> None:
+ req = ListDashboardsRequest.model_validate(
+ {"columns": ["id", "dashboard_title"]}
+ )
+ assert req.select_columns == ["id", "dashboard_title"]
Review Comment:
The dashboard request schema tests cover the list_* 'columns' alias, but not
the newly-intended 'columns' -> select_columns alias for
GetDashboardInfoRequest (once added). Adding this assertion would prevent
regressions and aligns with the PR's stated test plan.
##########
tests/unit_tests/mcp_service/dataset/test_dataset_schemas.py:
##########
@@ -0,0 +1,48 @@
+# 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.
+
+"""
+Unit tests for MCP dataset schema validation.
+"""
+
+from superset.mcp_service.dataset.schemas import (
+ GetDatasetInfoRequest,
+ ListDatasetsRequest,
+)
+
+
+class TestRequestSchemaAliasChoices:
+ """Test that LLM-friendly field name variants are accepted on the
+ dataset MCP tool request schemas, so callers sending 'id'/'dataset_id'
+ instead of 'identifier' (or 'columns' instead of 'select_columns')
+ don't silently have the field dropped."""
+
+ def test_get_dataset_info_identifier_id_alias(self) -> None:
+ req = GetDatasetInfoRequest.model_validate({"id": 42})
+ assert req.identifier == 42
+
+ def test_get_dataset_info_identifier_dataset_id_alias(self) -> None:
+ req = GetDatasetInfoRequest.model_validate({"dataset_id": 42})
+ assert req.identifier == 42
+
+ def test_get_dataset_info_identifier_still_works(self) -> None:
+ req = GetDatasetInfoRequest.model_validate({"identifier": 42})
+ assert req.identifier == 42
+
+ def test_list_datasets_select_columns_columns_alias(self) -> None:
+ req = ListDatasetsRequest.model_validate({"columns": ["id",
"table_name"]})
+ assert req.select_columns == ["id", "table_name"]
Review Comment:
The dataset request schema tests cover the list_* 'columns' alias, but not
the newly-intended 'columns' -> select_columns alias for GetDatasetInfoRequest
(once added). Adding this assertion would prevent regressions and aligns with
the PR's stated test plan.
--
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]