codeant-ai-for-open-source[bot] commented on code in PR #40359: URL: https://github.com/apache/superset/pull/40359#discussion_r3326670170
########## superset/mcp_service/report/tool/update_report.py: ########## @@ -0,0 +1,158 @@ +# 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. + +import logging +from typing import Any + +from fastmcp import Context +from superset_core.mcp.decorators import tool, ToolAnnotations + +from superset.extensions import event_logger +from superset.mcp_service.report.schemas import ( + UpdateReportRequest, + UpdateReportResponse, +) + +logger = logging.getLogger(__name__) + + +@tool( + tags=["mutate"], + class_permission_name="ReportSchedule", + method_permission_name="write", + annotations=ToolAnnotations( + title="Update a scheduled report or alert", + readOnlyHint=False, + destructiveHint=True, + ), +) +async def update_report( + request: UpdateReportRequest, ctx: Context +) -> UpdateReportResponse: + """Update an existing scheduled report or alert in Superset. + + Use this tool when the user wants to: + - Change the name, schedule, or recipients of an existing report or alert + - Enable or disable a schedule without deleting it + - Update the SQL condition or database for an existing alert + + Only fields explicitly provided in the request are changed; + all omitted fields retain their current values. + + Workflow: + 1. Get the report id from a previous create_report call or from the Superset UI + 2. Call this tool with the id and only the fields to change + 3. The returned id confirms which schedule was updated + """ + await ctx.info("Updating report schedule: id=%s" % (request.id,)) + + try: + # Deferred to avoid circular imports with the @tool decorator initialization + from superset.commands.report.exceptions import ( + ReportScheduleInvalidError, + ReportScheduleNotFoundError, + ReportScheduleUpdateFailedError, + ) + from superset.commands.report.update import UpdateReportScheduleCommand + from superset.mcp_service.utils.url_utils import get_superset_base_url + from superset.reports.models import ( + ReportRecipientType, + ReportScheduleType, + ) + + recipient_type_map = { + "Email": ReportRecipientType.EMAIL, + "Slack": ReportRecipientType.SLACK, + "SlackV2": ReportRecipientType.SLACKV2, + "Webhook": ReportRecipientType.WEBHOOK, + } + + recipients = None + if request.recipients is not None: + recipients = [ + { + "type": recipient_type_map[r.type], + "recipient_config_json": {"target": r.target}, + } + for r in request.recipients + ] + + all_props: dict[str, Any] = { + "name": request.name, + "crontab": request.crontab, + "active": request.active, + "description": request.description, + "timezone": request.timezone, + "dashboard": request.dashboard_id, + "chart": request.chart_id, + "database": request.database_id, + "sql": request.sql, + } + if request.type is not None: + all_props["type"] = ( + ReportScheduleType.ALERT + if request.type == "Alert" + else ReportScheduleType.REPORT + ) + if recipients is not None: + all_props["recipients"] = recipients + properties = {k: v for k, v in all_props.items() if v is not None} + Review Comment: **🟠Architect Review — HIGH** The partial-update filter drops every field whose value is None, which makes it impossible to intentionally clear nullable fields such as database_id; this prevents valid flows like converting an Alert to a Report, where the UpdateReportScheduleCommand requires database to be explicitly set to None. **Suggestion:** Preserve caller intent by distinguishing omitted fields from explicitly null ones (for example via Pydantic field-set tracking or exclude_unset) and forwarding explicit nulls through to UpdateReportScheduleCommand so transitions like Alert→Report can pass database=None as required by the command validation. [Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=8ba23ae7d086436699d1c1e3fc6d2024&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) | [Fix in VSCode Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=8ba23ae7d086436699d1c1e3fc6d2024&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 an **Architect / Logical Review** comment left during a code review. These reviews are first-class, important findings — not optional suggestions. Do NOT dismiss this as a 'big architectural change' just because the title says architect review; most of these can be resolved with a small, localized fix once the intent is understood. **Path:** superset/mcp_service/report/tool/update_report.py **Line:** 94:114 **Comment:** *HIGH: The partial-update filter drops every field whose value is None, which makes it impossible to intentionally clear nullable fields such as database_id; this prevents valid flows like converting an Alert to a Report, where the UpdateReportScheduleCommand requires database to be explicitly set to None. 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. If a suggested approach is provided above, use it as the authoritative instruction. If no explicit code suggestion is given, you MUST still draft and apply your own minimal, localized fix — do not punt back with 'no suggestion provided, review manually'. Keep the change as small as possible: add a guard clause, gate on a loading state, reorder an await, wrap in a conditional, etc. Do not refactor surrounding code or expand scope beyond the finding. 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> -- 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]
