codeant-ai-for-open-source[bot] commented on code in PR #40956: URL: https://github.com/apache/superset/pull/40956#discussion_r3493573527
########## 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: **Suggestion:** Add an explicit type annotation for the module-level logger variable to comply with the type-hint requirement for relevant variables. [custom_rule] **Severity Level:** Minor ⚠️ <details> <summary><b>Why it matters? 🤔 </b></summary> The file introduces a module-level logger variable without any type annotation. Under the custom Python type-hint rule, this is a relevant variable that can be annotated, so the suggestion identifies a real rule violation. </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=2a1a800b9941470dbd31d109ba2ef83f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=2a1a800b9941470dbd31d109ba2ef83f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** superset/mcp_service/dashboard/tool/delete_dashboard.py **Line:** 37:37 **Comment:** *Custom Rule: Add an explicit type annotation for the module-level logger variable to comply with the type-hint requirement for relevant variables. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40956&comment_hash=554751ab59c24071b568d9dc11af3d8cb59f30894d08e090abedc1404a3e3803&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40956&comment_hash=554751ab59c24071b568d9dc11af3d8cb59f30894d08e090abedc1404a3e3803&reaction=dislike'>👎</a> ########## 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: **Suggestion:** Annotate the dashboard lookup variable with its expected optional model type so this relevant local variable is explicitly typed. [custom_rule] **Severity Level:** Minor ⚠️ <details> <summary><b>Why it matters? 🤔 </b></summary> The lookup result is stored in a local variable without an explicit annotation. Because this is newly added Python code and the variable can be annotated with its optional dashboard type, it matches the type-hint requirement. </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=ee213051631542db81649794aa49da61&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=ee213051631542db81649794aa49da61&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** superset/mcp_service/dashboard/tool/delete_dashboard.py **Line:** 83:83 **Comment:** *Custom Rule: Annotate the dashboard lookup variable with its expected optional model type so this relevant local variable is explicitly typed. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40956&comment_hash=7d6864bfed78f44f75f516eb24e18d9fdd0dcca2f69ae4b7684ff0aac78e4e71&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40956&comment_hash=7d6864bfed78f44f75f516eb24e18d9fdd0dcca2f69ae4b7684ff0aac78e4e71&reaction=dislike'>👎</a> ########## tests/unit_tests/mcp_service/dashboard/tool/test_delete_dashboard.py: ########## @@ -0,0 +1,152 @@ +# 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 the delete_dashboard MCP tool. + +Covers: +- Successful delete (happy path) +- confirm=false refusal (safety gate) +- Dashboard not found +- Permission denied (user does not own the dashboard) +""" + +from unittest.mock import Mock, patch + +import pytest +from fastmcp import Client + +from superset.mcp_service.app import mcp + + [email protected] +def mcp_server() -> object: + """Return the FastMCP app instance for use in MCP client tests.""" + return mcp + + [email protected](autouse=True) Review Comment: **Suggestion:** Add an explicit return type annotation to this fixture function so it complies with the required type-hint rule for new Python functions. [custom_rule] **Severity Level:** Minor ⚠️ <details> <summary><b>Why it matters? 🤔 </b></summary> This is a newly added Python function without any type hint on its return value, which violates the rule requiring type hints on new or modified Python code when applicable. </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=f1ffb3e028d94f74b7c347413bce8844&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=f1ffb3e028d94f74b7c347413bce8844&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** tests/unit_tests/mcp_service/dashboard/tool/test_delete_dashboard.py **Line:** 42:42 **Comment:** *Custom Rule: Add an explicit return type annotation to this fixture function so it complies with the required type-hint rule for new Python functions. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40956&comment_hash=f3f1cccb01c9b544634054db1e0628bd6dc0e7fdca4aadff9818a49701c3e625&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40956&comment_hash=f3f1cccb01c9b544634054db1e0628bd6dc0e7fdca4aadff9818a49701c3e625&reaction=dislike'>👎</a> -- 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]
