codeant-ai-for-open-source[bot] commented on code in PR #40351: URL: https://github.com/apache/superset/pull/40351#discussion_r3326710666
########## superset/mcp_service/annotation_layer/tool/update_layer_annotation.py: ########## @@ -0,0 +1,153 @@ +# 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.annotation_layer.schemas import ( + UpdateLayerAnnotationRequest, + UpdateLayerAnnotationResponse, +) + +logger = logging.getLogger(__name__) + + +def _build_update_properties(request: UpdateLayerAnnotationRequest) -> dict[str, Any]: + """Build the properties dict for UpdateAnnotationCommand from the request.""" + properties: dict[str, Any] = {"layer": request.layer_id} + if request.short_descr is not None: + properties["short_descr"] = request.short_descr + if request.start_dttm is not None: + properties["start_dttm"] = request.start_dttm + if request.end_dttm is not None: + properties["end_dttm"] = request.end_dttm + if request.long_descr is not None: + properties["long_descr"] = request.long_descr Review Comment: **Suggestion:** This condition makes it impossible to clear a nullable description field: when a client explicitly sends `long_descr=null`, Pydantic sets it to `None` and this branch skips writing the field, so the previous value is kept instead of being cleared. Track whether a field was provided (for example via `model_fields_set`) and include `long_descr` in update properties when it is explicitly present, even if the value is `None`. [incomplete implementation] <details> <summary><b>Severity Level:</b> Major ⚠️</summary> ```mdx - ❌ MCP update tool cannot clear annotation long descriptions. - ⚠️ Charts keep outdated descriptions after attempted description clearing. ``` </details> <details> <summary><b>Steps of Reproduction ✅ </b></summary> ```mdx 1. Ensure there is an existing annotation with a non-null long description, for example by creating one via the MCP `create_layer_annotation` tool (see `superset/mcp_service/annotation_layer/tool/create_layer_annotation.py:49-76` and its test `test_create_layer_annotation_success` at `tests/unit_tests/mcp_service/annotation_layer/tool/test_create_layer_annotation.py:116-138`). 2. From an MCP client (as in the tests using `fastmcp.Client` at `tests/unit_tests/mcp_service/annotation_layer/tool/test_create_layer_annotation.py:44-59`), call the `update_layer_annotation` tool (`superset/mcp_service/annotation_layer/tool/update_layer_annotation.py:59-76`) with a request payload containing the existing `layer_id` and `annotation_id` plus `"long_descr": null` in the JSON arguments. 3. The request is parsed into `UpdateLayerAnnotationRequest` (`superset/mcp_service/annotation_layer/schemas.py:109-145`), where `long_descr` is typed as `str | None` with a default of `None` (line 138); whether the client omitted `long_descr` or provided it as `null`, the resulting `request.long_descr` value is `None`. 4. Inside `update_layer_annotation`, `_build_update_properties` is called (`superset/mcp_service/annotation_layer/tool/update_layer_annotation.py:33-46`); because `request.long_descr is None`, the condition at lines 42-43 is false, so `"long_descr"` is omitted from the `properties` dict passed to `UpdateAnnotationCommand` (`superset/commands/annotation_layer/annotation/update.py:41-52`), and `BaseDAO.update` only sets attributes present in `properties` (`superset/daos/base.py:14-31`), leaving the existing `Annotation.long_descr` field (`superset/models/annotations.py:41-51`) unchanged instead of clearing it to NULL. ``` </details> [Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=fb531bcebf434d71bb633c642a707266&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=fb531bcebf434d71bb633c642a707266&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/annotation_layer/tool/update_layer_annotation.py **Line:** 42:43 **Comment:** *Incomplete Implementation: This condition makes it impossible to clear a nullable description field: when a client explicitly sends `long_descr=null`, Pydantic sets it to `None` and this branch skips writing the field, so the previous value is kept instead of being cleared. Track whether a field was provided (for example via `model_fields_set`) and include `long_descr` in update properties when it is explicitly present, even if the value is `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. 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%2F40351&comment_hash=08e717abe1f9fedb9d583c33ef42aaedec6bc2036216437af3ce47a8948b7760&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40351&comment_hash=08e717abe1f9fedb9d583c33ef42aaedec6bc2036216437af3ce47a8948b7760&reaction=dislike'>👎</a> ########## superset/mcp_service/annotation_layer/tool/update_layer_annotation.py: ########## @@ -0,0 +1,153 @@ +# 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.annotation_layer.schemas import ( + UpdateLayerAnnotationRequest, + UpdateLayerAnnotationResponse, +) + +logger = logging.getLogger(__name__) + + +def _build_update_properties(request: UpdateLayerAnnotationRequest) -> dict[str, Any]: + """Build the properties dict for UpdateAnnotationCommand from the request.""" + properties: dict[str, Any] = {"layer": request.layer_id} + if request.short_descr is not None: + properties["short_descr"] = request.short_descr + if request.start_dttm is not None: + properties["start_dttm"] = request.start_dttm + if request.end_dttm is not None: + properties["end_dttm"] = request.end_dttm + if request.long_descr is not None: + properties["long_descr"] = request.long_descr + if request.json_metadata is not None: + properties["json_metadata"] = request.json_metadata Review Comment: **Suggestion:** This check drops explicit `json_metadata=null` updates, so callers cannot clear existing metadata. Because omitted and explicit-null both become `None` in the request model, you need to detect field presence separately and pass `json_metadata` through when the client intentionally provided it. [incomplete implementation] <details> <summary><b>Severity Level:</b> Major ⚠️</summary> ```mdx - ❌ MCP update tool cannot clear annotation JSON metadata. - ⚠️ Charts continue using stale metadata for native annotations. ``` </details> <details> <summary><b>Steps of Reproduction ✅ </b></summary> ```mdx 1. Ensure there is an existing annotation with non-null `json_metadata`, for example by creating one via `create_layer_annotation` with `json_metadata='{\"severity\": \"high\"}'` (see test `test_create_layer_annotation_optional_fields_forwarded` at `tests/unit_tests/mcp_service/annotation_layer/tool/test_create_layer_annotation.py:221-249` which shows metadata being forwarded to `CreateAnnotationCommand`). 2. From an MCP client (pattern as in `tests/unit_tests/mcp_service/annotation_layer/tool/test_create_layer_annotation.py:44-59`), call the `update_layer_annotation` tool (`superset/mcp_service/annotation_layer/tool/update_layer_annotation.py:59-76`) with a JSON payload that includes the existing `layer_id` and `annotation_id` plus `"json_metadata": null` to intentionally clear metadata. 3. The payload is parsed into `UpdateLayerAnnotationRequest` (`superset/mcp_service/annotation_layer/schemas.py:109-145`), where `json_metadata` is declared as `str | None` with default `None` and validated by `validate_json_metadata` (lines 142-155); a JSON `null` input becomes `request.json_metadata is None`, passes the `if v is None: return v` branch, and no error is raised. 4. In `_build_update_properties` (`superset/mcp_service/annotation_layer/tool/update_layer_annotation.py:33-46`), the condition at lines 44-45 `if request.json_metadata is not None` is false, so `"json_metadata"` is omitted from the `properties` dict given to `UpdateAnnotationCommand.run` (`superset/commands/annotation_layer/annotation/update.py:41-52`), and because `BaseDAO.update` only sets attributes present in that dict (`superset/daos/base.py:14-31`), the existing `Annotation.json_metadata` (`superset/models/annotations.py:41-53`) is left unchanged instead of being cleared, so metadata cannot be unset via explicit `null`. ``` </details> [Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=b6c15a2bb88d4fadaa36ade6ceff182d&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=b6c15a2bb88d4fadaa36ade6ceff182d&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/annotation_layer/tool/update_layer_annotation.py **Line:** 44:45 **Comment:** *Incomplete Implementation: This check drops explicit `json_metadata=null` updates, so callers cannot clear existing metadata. Because omitted and explicit-null both become `None` in the request model, you need to detect field presence separately and pass `json_metadata` through when the client intentionally provided it. 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%2F40351&comment_hash=df94e75aff729356db12e1ce2495c9fa8d5da15399e749ca63a7289a2dc8c812&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40351&comment_hash=df94e75aff729356db12e1ce2495c9fa8d5da15399e749ca63a7289a2dc8c812&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]
