codeant-ai-for-open-source[bot] commented on code in PR #42002:
URL: https://github.com/apache/superset/pull/42002#discussion_r3571901246
##########
superset/mcp_service/dashboard/tool/update_dashboard.py:
##########
@@ -260,6 +292,20 @@ def _validate_update_request(
error_type="DatabaseError",
)
+ # A non-empty owners list must reference existing users. An empty list is
+ # a valid "clear all owners" request and needs no lookup.
+ if request.owners:
+ _users, missing = _resolve_owners(request.owners)
+ if missing:
+ return DashboardError(
+ error=(
+ "Unknown owner user IDs: "
+ + ", ".join(str(m) for m in missing)
+ + ". Find valid IDs with list_users."
+ ),
+ error_type="OwnersNotFound",
+ )
Review Comment:
**Suggestion:** Owner validation does database lookups without handling
database exceptions, and this block runs before the tool’s SQLAlchemy error
wrapper. If the user lookup query fails (for example during transient DB
issues), the exception escapes as an unhandled tool failure instead of
returning the structured `DatabaseError` response used elsewhere in this
function. Wrap owner resolution in `except SQLAlchemyError` and return a
consistent `DashboardError`. [logic error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Owner validation can crash update_dashboard on database errors.
- ⚠️ MCP clients receive unstructured internal errors for owner lookups.
- ⚠️ Owner changes unavailable during transient database connectivity issues.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Invoke the MCP `update_dashboard` tool defined at
`superset/mcp_service/dashboard/tool/update_dashboard.py:63` with a request
containing a
non-empty `owners` list (e.g. via FastMCP client invoking the
`update_dashboard` tool).
2. The tool resolves the target dashboard via
`_find_and_authorize_dashboard` at
`update_dashboard.py:53-99`, then calls `_validate_update_request(dashboard,
request)` at
`update_dashboard.py:362-364` **outside** the surrounding `try/except
SQLAlchemyError`
block that begins at `update_dashboard.py:112`.
3. Inside `_validate_update_request` at `update_dashboard.py:241-250`, when
it reaches the
owners validation block at `update_dashboard.py:295-308`, it calls
`_resolve_owners(request.owners)` (definition at
`update_dashboard.py:156-177`), which in
turn performs `security_manager.get_user_by_id(uid)` using SQLAlchemy-backed
models.
4. During this lookup, simulate a transient database failure (e.g.
disconnect or statement
error) so that `security_manager.get_user_by_id` raises `SQLAlchemyError`;
because this
occurs in `_validate_update_request` before any local `try/except
SQLAlchemyError` and
before the main `update_dashboard` `try/except SQLAlchemyError` (which only
wraps
`_apply_field_updates` and `db.session.commit` at
`update_dashboard.py:112-153`), the
exception bubbles up unhandled, causing the MCP tool call to fail with an
internal error
instead of returning a structured
`DashboardError(error_type="DatabaseError")` like the
tag-validation block at `update_dashboard.py:22-34`.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=df7c301fc1864762be532188239574d4&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=df7c301fc1864762be532188239574d4&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/update_dashboard.py
**Line:** 297:307
**Comment:**
*Logic Error: Owner validation does database lookups without handling
database exceptions, and this block runs before the tool’s SQLAlchemy error
wrapper. If the user lookup query fails (for example during transient DB
issues), the exception escapes as an unhandled tool failure instead of
returning the structured `DatabaseError` response used elsewhere in this
function. Wrap owner resolution in `except SQLAlchemyError` and return a
consistent `DashboardError`.
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%2F42002&comment_hash=23e87834919d5f6a1f7ed03ed754bd5710b57387117b0b0eedbc2c7911064878&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42002&comment_hash=23e87834919d5f6a1f7ed03ed754bd5710b57387117b0b0eedbc2c7911064878&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]