codeant-ai-for-open-source[bot] commented on code in PR #40956: URL: https://github.com/apache/superset/pull/40956#discussion_r3539877046
########## superset/mcp_service/dashboard/tool/delete_dashboard.py: ########## @@ -0,0 +1,144 @@ +# 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: delete_dashboard + +This tool permanently deletes a dashboard. It requires an explicit +``confirm=true`` safety gate so callers must state destructive intent. +""" + +import logging + +from fastmcp import Context +from superset_core.mcp.decorators import tool, ToolAnnotations + +from superset.extensions import event_logger +from superset.mcp_service.dashboard.schemas import ( + DeleteDashboardRequest, + DeleteDashboardResponse, + DeletedDashboardSummary, +) + +logger = logging.getLogger(__name__) Review Comment: ✅ **Customized review instruction saved!** **Instruction:** > Do not require explicit type annotations for module-level logger declarations in the superset/mcp_service codebase; use the standard `logger = logging.getLogger(__name__)` convention to stay consistent with sibling files. **Applied to:** - `superset/mcp_service/**` --- 💡 *To manage or update this instruction, visit: [CodeAnt AI Settings](https://app.codeant.ai/org/settings/learnings)* ########## superset/mcp_service/dashboard/tool/delete_dashboard.py: ########## @@ -0,0 +1,144 @@ +# 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: delete_dashboard + +This tool permanently deletes a dashboard. It requires an explicit +``confirm=true`` safety gate so callers must state destructive intent. +""" + +import logging + +from fastmcp import Context +from superset_core.mcp.decorators import tool, ToolAnnotations + +from superset.extensions import event_logger +from superset.mcp_service.dashboard.schemas import ( + DeleteDashboardRequest, + DeleteDashboardResponse, + DeletedDashboardSummary, +) + +logger = logging.getLogger(__name__) + + +@tool( + tags=["mutate"], + class_permission_name="Dashboard", + method_permission_name="write", + annotations=ToolAnnotations( + title="Delete dashboard", + readOnlyHint=False, + destructiveHint=True, + ), +) +async def delete_dashboard( + request: DeleteDashboardRequest, ctx: Context +) -> DeleteDashboardResponse: + """ + Permanently delete a dashboard by ID. The charts on the dashboard are + NOT deleted — only the dashboard itself. This action cannot be undone, + so the tool refuses to run unless ``confirm=true`` is explicitly passed. + """ + from superset.commands.dashboard.delete import DeleteDashboardCommand + from superset.commands.dashboard.exceptions import ( + DashboardDeleteFailedError, + DashboardForbiddenError, + DashboardNotFoundError, + ) + from superset.daos.dashboard import DashboardDAO + + if not request.confirm: + await ctx.warning( + "Deletion of dashboard %s not confirmed" % (request.dashboard_id,) + ) + return DeleteDashboardResponse( + deleted=False, + dashboard=None, + error=( + f"Deletion not confirmed. Deleting dashboard " + f"{request.dashboard_id} is permanent and cannot be undone. " + "Re-run with confirm=true to proceed." + ), + ) + + summary: DeletedDashboardSummary | None = None + try: + with event_logger.log_context(action="mcp.delete_dashboard.validation"): + dashboard = DashboardDAO.find_by_id(request.dashboard_id) Review Comment: ✅ **Customized review instruction saved!** **Instruction:** > Do not require explicit local type annotations when the variable’s type is already inferred from an annotated return value and narrowed by a guard; this matches the existing style in dashboard tool files. **Applied to:** - `superset/mcp_service/dashboard/tool/**` --- 💡 *To manage or update this instruction, visit: [CodeAnt AI Settings](https://app.codeant.ai/org/settings/learnings)* -- 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]
