aminghadersohi commented on code in PR #40746:
URL: https://github.com/apache/superset/pull/40746#discussion_r3370496387
##########
superset/mcp_service/user/schemas.py:
##########
@@ -104,6 +107,31 @@ class UserInfo(BaseModel):
"access via get_user_info; not available in list_users because roles "
"is a relationship, not a selectable column)",
)
+
+ @field_validator("roles", mode="before")
+ @classmethod
+ def _extract_role_names(cls, v: Any) -> list[str] | None:
+ """Coerce Role ORM objects to their .name strings."""
+ if v is None:
+ return None
+ if isinstance(v, str):
+ # Preserve Pydantic's default rejection of bare strings for
list[str].
+ raise ValueError("roles must be a list, not a string")
+ result: list[str] = []
+ for item in v:
+ if isinstance(item, str):
+ result.append(item)
+ continue
+ try:
+ if hasattr(item, "name") and isinstance(item.name, str):
+ result.append(item.name)
+ except DetachedInstanceError:
+ logger.debug(
+ "Skipping role with detached instance in UserInfo.roles
coercion"
+ )
+ continue
Review Comment:
NIT — `continue` is the last statement in the loop body here; there's
nothing after the `try/except` block within the `for item in v` loop, so this
is a no-op. Remove it.
##########
superset/mcp_service/user/schemas.py:
##########
@@ -19,9 +19,12 @@
from __future__ import annotations
+import logging
from datetime import datetime, timezone
from typing import Annotated, Any, List, Literal
+logger = logging.getLogger(__name__)
Review Comment:
HIGH — `logger = logging.getLogger(__name__)` sits between the stdlib
imports and the third-party imports. Ruff E402 fires on the `from pydantic
import (` block at line 28. Pre-commit CI is failing on this branch because of
this ordering.
Move the logger assignment to after all imports (after the last `from
superset.mcp_service.utils.schema_utils import ...` line).
```suggestion
```
Delete this line here and add `logger = logging.getLogger(__name__)` after
line 47 (after the last import).
--
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]