dosubot[bot] commented on issue #41001:
URL: https://github.com/apache/superset/issues/41001#issuecomment-4710447795
<!-- Answer -->
@sadpandajoe I've confirmed this bug is valid. Here's the summary:
**Root Cause Confirmed**
In `superset/mcp_service/dashboard/schemas.py`, the `dashboard_serializer()`
function uses `RoleInfo.model_validate(role, from_attributes=True)` to
serialize dashboard roles . Since `RoleInfo.permissions` is typed as `List[str]
| None` , Pydantic attempts to coerce `PermissionView` ORM objects into
strings, which triggers a lazy load of `PermissionView.permission` — and
because the MCP ASGI sub-app has already detached the SQLAlchemy session, this
raises `DetachedInstanceError`.
**The fix already exists in the same file** — `serialize_role_object()`
correctly extracts permission names as strings:
```python
permissions=[perm.name for perm in getattr(role, "permissions", [])]
```
**Recommended Fix**
Replace the `model_validate` calls in `dashboard_serializer()` (and any
other serialization paths like `build_dashboard_info()`) with the existing
helper:
```python
# Before (broken):
roles=[
RoleInfo.model_validate(role, from_attributes=True)
for role in dashboard.roles
]
# After (fixed):
roles=[
serialize_role_object(role)
for role in dashboard.roles
]
```
This is consistent with how other ORM objects are serialized in the MCP
service (e.g., `serialize_user_object`, `serialize_tag_object`,
`serialize_chart_object` all follow the helper pattern). The
`model_validate(..., from_attributes=True)` approach is simply incompatible
with lazy-loaded nested relationships in the detached-session context of the
MCP ASGI sub-app.
A related issue was also reported in
[#40423](https://github.com/apache/superset/issues/40423) with the same
`DetachedInstanceError` on `PermissionView` in `list_dashboards`.
<!-- Dosu Comment Footer -->
*To reply, just mention
[@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fsuperset).*
---
Share context across your team and agents. Try
[Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-tagline&utm_term=apache%2Fsuperset).
[](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-feedback&utm_term=apache%2Fsuperset&message_id=71dda9c4-2b96-4db3-aeec-a43d886a27c8)
[](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-learn-repo&utm_term=apache%2Fsuperset)
[](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-add-team&utm_term=apache%2Fsuperset)
--
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]