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


##########
superset/daos/dashboard.py:
##########
@@ -431,7 +431,8 @@ def update_native_filters_config(
             raise DashboardUpdateFailedError("Dashboard not found")
 
         if attributes:
-            metadata = json.loads(dashboard.json_metadata or "{}")
+            _parsed = json.loads(dashboard.json_metadata or "{}")
+            metadata = _parsed if isinstance(_parsed, dict) else {}

Review Comment:
   Same as the `_parsed` note above — mypy infers this correctly and the 
codebase doesn't annotate local variables of this shape.



##########
superset/mcp_service/dashboard/tool/manage_native_filters.py:
##########
@@ -0,0 +1,508 @@
+# 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.
+
+"""
+MCP tool: manage_native_filters
+
+Adds, updates, removes, and reorders native filters on a dashboard by
+translating high-level operations into the ``deleted`` / ``modified`` /
+``reordered`` payload consumed by ``UpdateDashboardNativeFiltersCommand``.
+"""
+
+import copy
+import logging
+from typing import Any, cast
+
+from fastmcp import Context
+from superset_core.mcp.decorators import tool, ToolAnnotations
+
+from superset.extensions import event_logger
+from superset.mcp_service.dashboard.constants import generate_id
+from superset.mcp_service.dashboard.schemas import (
+    FilterSelectSpec,
+    FilterTimeSpec,
+    ManageNativeFiltersRequest,
+    ManageNativeFiltersResponse,
+    NativeFilterSummary,
+    NativeFilterUpdateSpec,
+)
+from superset.mcp_service.utils import (
+    escape_llm_context_delimiters,
+    sanitize_for_llm_context,
+)
+from superset.mcp_service.utils.url_utils import get_superset_base_url
+from superset.utils import json
+
+logger = logging.getLogger(__name__)

Review Comment:
   Declining: module-level loggers are intentionally unannotated across the 
entire Superset codebase (`logger = logging.getLogger(__name__)` is the 
standard pattern). Adding `: logging.Logger` here would be inconsistent with 
every other file.



##########
superset/mcp_service/dashboard/schemas.py:
##########
@@ -1512,3 +1512,217 @@ def dashboard_layout_serializer(dashboard: "Dashboard") 
-> DashboardLayout:
             has_layout=bool(position_json_str),
         )
     )
+
+
+# ---------------------------------------------------------------------------
+# manage_native_filters schemas
+# ---------------------------------------------------------------------------
+
+
+class BaseNewFilterSpec(BaseModel):
+    """Common fields shared by all new native filter specs."""
+
+    name: str = Field(..., min_length=1, description="Filter display name")
+    description: str = Field("", description="Optional filter description")
+    scope_chart_ids: List[int] | None = Field(
+        None,
+        description=(
+            "Chart IDs this filter should apply to. When omitted the filter "
+            "applies to all charts on the dashboard. All IDs must belong to "
+            "charts that are on the dashboard."
+        ),
+    )
+
+
+class FilterSelectSpec(BaseNewFilterSpec):
+    """Spec for a new dropdown (filter_select) native filter."""
+
+    filter_type: Literal["filter_select"] = Field(
+        ..., description="Discriminator - must be 'filter_select'"
+    )
+    dataset_id: int = Field(..., description="ID of the dataset to filter on")
+    column: str = Field(
+        ..., min_length=1, description="Name of the dataset column to filter 
on"
+    )
+    multi_select: bool = Field(
+        True, description="Allow selecting multiple values (default True)"
+    )
+    default_to_first_item: bool = Field(
+        False, description="Default the filter to the first item in the list"
+    )
+    enable_empty_filter: bool = Field(
+        False, description="Require a value before the filter is applied"
+    )
+    sort_ascending: bool | None = Field(
+        None,
+        description=(
+            "Sort filter values ascending (True) or descending (False). "
+            "When omitted, values are not explicitly sorted."
+        ),
+    )
+    search_all_options: bool = Field(
+        False, description="Query the database on search rather than 
client-side"
+    )
+
+
+class FilterTimeSpec(BaseNewFilterSpec):
+    """Spec for a new time range (filter_time) native filter."""
+
+    filter_type: Literal["filter_time"] = Field(
+        ..., description="Discriminator - must be 'filter_time'"
+    )
+    default_time_range: str | None = Field(
+        None,
+        description=(
+            "Default time range value, e.g. 'Last week', 'Last month', "
+            "'2024-01-01 : 2024-12-31'. When omitted the filter has no 
default."
+        ),
+    )
+
+
+NewNativeFilterSpec = Annotated[
+    FilterSelectSpec | FilterTimeSpec,
+    Field(discriminator="filter_type"),
+]

Review Comment:
   Declining: `TypeAlias` annotation on `NewNativeFilterSpec` is not the 
existing pattern in this schemas file — other `Annotated` type aliases here 
(e.g. for other discriminated unions) are written the same way. Leaving 
consistent.



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