codeant-ai-for-open-source[bot] commented on code in PR #40352:
URL: https://github.com/apache/superset/pull/40352#discussion_r3326669299


##########
superset/mcp_service/annotation_layer/schemas.py:
##########
@@ -0,0 +1,73 @@
+# 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.
+
+"""
+Pydantic schemas for annotation layer MCP tools
+"""
+
+from __future__ import annotations
+
+from pydantic import BaseModel, ConfigDict, Field
+
+
+class CreateAnnotationLayerRequest(BaseModel):
+    model_config = ConfigDict(populate_by_name=True)
+
+    name: str = Field(
+        ...,
+        min_length=1,
+        max_length=250,
+        description="Unique name for the annotation layer",
+    )
+    descr: str | None = Field(
+        None, description="Optional description of the annotation layer"
+    )
+
+
+class CreateAnnotationLayerResponse(BaseModel):
+    id: int | None = Field(
+        None,
+        description="ID of the created annotation layer, or None if failed",
+    )
+    name: str = Field(..., description="Name of the annotation layer")
+    descr: str | None = Field(None, description="Description of the annotation 
layer")
+    error: str | None = Field(None, description="Error message if creation 
failed")
+
+
+class UpdateAnnotationLayerRequest(BaseModel):
+    model_config = ConfigDict(populate_by_name=True)
+
+    id: int = Field(..., description="ID of the annotation layer to update")
+    name: str | None = Field(
+        None,
+        min_length=1,
+        max_length=250,
+        description="New name for the annotation layer",
+    )
+    descr: str | None = Field(
+        None, description="New description for the annotation layer"

Review Comment:
   **Suggestion:** `UpdateAnnotationLayerRequest` does not enforce the 
documented contract that at least one mutable field must be provided. As 
written, callers can send only `id`, which produces an empty update payload and 
can result in a no-op "successful" update instead of a validation error. Add a 
model-level validator to reject requests where both `name` and `descr` are 
`None`. [incomplete implementation]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ update_annotation_layer accepts id-only, contrary to tool contract.
   - ⚠️ Clients see success despite no changes being applied.
   - ⚠️ LLM workflows may misinterpret silent no-op as update.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Observe the request schema in 
`superset/mcp_service/annotation_layer/schemas.py:51-63`
   where `UpdateAnnotationLayerRequest` defines `id` as required and 
`name`/`descr` as
   optional with no model-level validator enforcing that at least one of them 
be non-null.
   
   2. In an MCP client (mirroring
   
`tests/unit_tests/mcp_service/annotation_layer/tool/test_update_annotation_layer.py:101-117`),
   construct a request `UpdateAnnotationLayerRequest(id=7)` without `name` or 
`descr` and
   call the tool via `await client.call_tool("update_annotation_layer", 
{"request":
   request.model_dump()})`.
   
   3. The tool handler `update_annotation_layer` in
   
`superset/mcp_service/annotation_layer/tool/update_annotation_layer.py:43-76` 
builds
   `properties: dict[str, Any] = {}` and, because `request.name` and 
`request.descr` are both
   `None`, leaves `properties` empty (lines 69-73) but still calls
   `UpdateAnnotationLayerCommand(request.id, properties).run()`.
   
   4. `UpdateAnnotationLayerCommand.run` in
   `superset/commands/annotation_layer/update.py:38-19` calls
   `AnnotationLayerDAO.update(self._model, self._properties)` with an empty 
dict, and
   `BaseDAO.update` in `superset/daos/base.py:407-30` performs no attribute 
updates when
   `attributes` is falsy, returning the existing model; control returns to the 
MCP tool which
   then constructs a successful `UpdateAnnotationLayerResponse` at
   
`superset/mcp_service/annotation_layer/tool/update_annotation_layer.py:82-86` 
with
   unchanged values and no `error`, violating the documented contract in the 
tool docstring
   (lines 46-50: "At least one of ``name`` or ``descr`` must be provided.").
   ```
   </details>
   
   [Fix in 
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=134ff51247494da797f2e5ada7a01462&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=134ff51247494da797f2e5ada7a01462&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/schemas.py
   **Line:** 54:62
   **Comment:**
        *Incomplete Implementation: `UpdateAnnotationLayerRequest` does not 
enforce the documented contract that at least one mutable field must be 
provided. As written, callers can send only `id`, which produces an empty 
update payload and can result in a no-op "successful" update instead of a 
validation error. Add a model-level validator to reject requests where both 
`name` and `descr` are `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%2F40352&comment_hash=3a3bb064ccf822883d44124e4aa704d10a8b63c53c393a9eebcb83b44407b864&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40352&comment_hash=3a3bb064ccf822883d44124e4aa704d10a8b63c53c393a9eebcb83b44407b864&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]

Reply via email to