aminghadersohi commented on code in PR #41855:
URL: https://github.com/apache/superset/pull/41855#discussion_r3574263679


##########
superset/mcp_service/mcp_core.py:
##########
@@ -284,8 +315,31 @@ def _call_dao_list(
             search=search,
             search_columns=self.search_columns,
             columns=columns_to_load,
+            custom_filters=custom_filters,
         )
 
+    def _build_deleted_state_filter(
+        self, deleted_state: str | None
+    ) -> DeletedStateBoundFilter | None:
+        """Validate deleted_state and bind it to the entity's FAB filter.
+
+        Returns None when trash listing was not requested. Raises for a
+        value other than ``include``/``only`` or when the resource has no
+        deleted-state filter configured.
+        """
+        if deleted_state is None:
+            return None
+        normalized = str(deleted_state).lower().strip()
+        if normalized not in {"include", "only"}:
+            raise ValueError("deleted_state must be 'include' or 'only'")

Review Comment:
   MEDIUM: codecov reports only 24.32% patch coverage / 26 lines missing in 
this file. The two `_build_deleted_state_filter` error branches (invalid value, 
resource without a configured `deleted_state_filter`) aren't exercised by any 
test — the MCP-layer "invalid value" test is actually caught by pydantic's 
`Literal["include","only"]` at the schema layer before this function ever runs, 
so this defensive fallback path itself is untested. Since this is 
shared/reusable code, consider a direct unit test calling 
`ModelListCore.run_tool(deleted_state=...)` (or a resource with 
`deleted_state_filter=None`) to prove the fallback itself raises correctly.



##########
tests/unit_tests/mcp_service/dashboard/tool/test_list_dashboards_deleted_state.py:
##########
@@ -0,0 +1,132 @@
+# 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 list_dashboards ``deleted_state`` trash listing.
+
+Mirrors the list_charts deleted_state tests: DAO custom filter pass-through,
+session-scoped visibility bypass around the DAO call, and ``deleted_at``
+forced into loaded columns and the serialized response.
+"""
+
+from collections.abc import Iterator
+from datetime import datetime
+from unittest.mock import MagicMock, Mock, patch
+from uuid import UUID
+
+import pytest
+from fastmcp import Client
+
+from superset.mcp_service.app import mcp
+from superset.utils import json
+
+_DAO_LIST = "superset.daos.dashboard.DashboardDAO.list"
+_BYPASS = "superset.mcp_service.mcp_core.skip_visibility_filter"
+
+
[email protected]
+def mcp_server() -> object:
+    return mcp
+
+
[email protected](autouse=True)
+def mock_auth() -> Iterator[Mock]:
+    with patch("superset.mcp_service.auth.get_user_from_request") as 
mock_get_user:
+        mock_user = Mock()
+        mock_user.id = 1
+        mock_user.username = "admin"
+        mock_get_user.return_value = mock_user
+        yield mock_get_user
+
+
+def _trashed_dashboard_row() -> Mock:
+    row = Mock(
+        spec=[
+            "id",
+            "dashboard_title",
+            "slug",
+            "published",
+            "changed_on",
+            "created_on",
+            "uuid",
+            "deleted_at",
+        ]
+    )
+    row.id = 1
+    row.dashboard_title = "Trashed Dashboard"
+    row.slug = None
+    row.published = False
+    row.changed_on = datetime(2026, 6, 1)
+    row.created_on = datetime(2026, 5, 1)
+    row.uuid = UUID("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")
+    row.deleted_at = datetime(2026, 7, 1)
+    return row
+
+
+@patch(_DAO_LIST)
[email protected]
+async def test_list_dashboards_deleted_state_only_passes_custom_filter(
+    mock_list: Mock, mcp_server: object
+) -> None:
+    mock_list.return_value = ([], 0)
+
+    async with Client(mcp_server) as client:
+        await client.call_tool(
+            "list_dashboards", {"request": {"deleted_state": "only"}}
+        )
+
+    kwargs = mock_list.call_args.kwargs
+    assert "deleted_state" in (kwargs.get("custom_filters") or {})
+    assert "deleted_at" in kwargs["columns"]
+
+
+@patch(_BYPASS)
+@patch(_DAO_LIST)
[email protected]
+async def test_list_dashboards_deleted_state_wraps_visibility_bypass(
+    mock_list: Mock, mock_bypass: MagicMock, mcp_server: object
+) -> None:
+    from superset.models.dashboard import Dashboard
+
+    mock_list.return_value = ([], 0)
+    mock_bypass.return_value.__enter__ = Mock(return_value=None)
+    mock_bypass.return_value.__exit__ = Mock(return_value=False)
+
+    async with Client(mcp_server) as client:
+        await client.call_tool(
+            "list_dashboards", {"request": {"deleted_state": "include"}}
+        )
+
+    mock_bypass.assert_called_once()
+    assert Dashboard in mock_bypass.call_args.args
+
+
+@patch(_DAO_LIST)
[email protected]
+async def test_list_dashboards_deleted_state_serializes_deleted_at(
+    mock_list: Mock, mcp_server: object
+) -> None:
+    mock_list.return_value = ([_trashed_dashboard_row()], 1)
+
+    async with Client(mcp_server) as client:
+        result = await client.call_tool(
+            "list_dashboards", {"request": {"deleted_state": "only"}}
+        )
+
+    data = json.loads(result.content[0].text)
+    assert data["dashboards"][0]["id"] == 1
+    assert data["dashboards"][0]["deleted_at"] is not None
+    assert "deleted_at" in data["columns_loaded"]

Review Comment:
   NIT: this file is missing three tests present in the chart-side file 
(`test_list_charts_default_has_no_deleted_state_filter`, 
`test_list_charts_no_deleted_state_no_visibility_bypass`, 
`test_list_charts_deleted_state_invalid_value_rejected`). Low functional risk 
since the validated code path is shared in `mcp_core.py`, but worth adding for 
parity and to catch a future divergence between the two tools.



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