You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2026/06/01 17:24:34 UTC

(superset) 07/11: test(mcp): add DatasetInvalidError test; add min_length to table_name

This is an automated email from the ASF dual-hosted git repository.

aminghadersohi pushed a commit to branch aminghadersohi/mcp-create-dataset
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 75789601e7d55c62b17ef635a222aa4bf5007a39
Author: Amin Ghadersohi <am...@gmail.com>
AuthorDate: Thu May 28 08:00:58 2026 +0000

    test(mcp): add DatasetInvalidError test; add min_length to table_name
    
    - Add test_create_dataset_invalid_error to cover the DatasetInvalidError
      handler in create_dataset (previously untested path)
    - Add min_length=1 to CreateDatasetRequest.table_name to reject empty
      strings at the schema layer, consistent with CreateVirtualDatasetRequest
    
    Co-Authored-By: Claude Sonnet 4.6 <no...@anthropic.com>
---
 superset/mcp_service/dataset/schemas.py            |  5 ++++-
 .../dataset/tool/test_create_dataset.py            | 26 ++++++++++++++++++++++
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/superset/mcp_service/dataset/schemas.py b/superset/mcp_service/dataset/schemas.py
index c3faa8db112..5decba8be79 100644
--- a/superset/mcp_service/dataset/schemas.py
+++ b/superset/mcp_service/dataset/schemas.py
@@ -343,7 +343,10 @@ class CreateDatasetRequest(BaseModel):
     ]
     table_name: Annotated[
         str,
-        Field(description="Name of the physical table to register as a dataset"),
+        Field(
+            min_length=1,
+            description="Name of the physical table to register as a dataset",
+        ),
     ]
     owners: Annotated[
         List[int] | None,
diff --git a/tests/unit_tests/mcp_service/dataset/tool/test_create_dataset.py b/tests/unit_tests/mcp_service/dataset/tool/test_create_dataset.py
index 9123abaf53d..c04aea88139 100644
--- a/tests/unit_tests/mcp_service/dataset/tool/test_create_dataset.py
+++ b/tests/unit_tests/mcp_service/dataset/tool/test_create_dataset.py
@@ -209,6 +209,32 @@ class TestCreateDataset:
         data = json.loads(result.content[0].text)
         assert data["error_type"] == "TableNotFoundError"
 
+    @patch("superset.commands.dataset.create.CreateDatasetCommand")
+    @pytest.mark.asyncio
+    async def test_create_dataset_invalid_error(self, mock_command_class, mcp_server):
+        """DatasetInvalidError is returned as ValidationError type."""
+        from superset.commands.dataset.exceptions import DatasetInvalidError
+
+        mock_command = MagicMock()
+        mock_command.run.side_effect = DatasetInvalidError()
+        mock_command_class.return_value = mock_command
+
+        async with Client(mcp_server) as client:
+            result = await client.call_tool(
+                "create_dataset",
+                {
+                    "request": {
+                        "database_id": 1,
+                        "schema": "public",
+                        "table_name": "orders",
+                    }
+                },
+            )
+
+        data = json.loads(result.content[0].text)
+        assert data["error_type"] == "ValidationError"
+        assert "error" in data
+
     @patch("superset.commands.dataset.create.CreateDatasetCommand")
     @pytest.mark.asyncio
     async def test_create_dataset_unexpected_error(