goingforstudying-ctrl commented on code in PR #40746:
URL: https://github.com/apache/superset/pull/40746#discussion_r3408690551
##########
superset/mcp_service/user/schemas.py:
##########
@@ -277,9 +305,17 @@ def serialize_user_object(
if include_sensitive and include_roles:
user_roles = getattr(user, "roles", None)
if user_roles is not None:
- try:
- roles = [r.name for r in user_roles if hasattr(r, "name")]
- except (AttributeError, DetachedInstanceError):
+ roles = []
+ for r in user_roles:
+ try:
+ if hasattr(r, "name") and isinstance(r.name, str):
+ roles.append(escape_llm_context_delimiters(r.name))
+ except (AttributeError, DetachedInstanceError):
+ logger.debug(
+ "Skipping role that raised exception in
serialize_user_object"
+ )
+ continue
+ if not roles:
roles = None
Review Comment:
Fixed in latest commit. Removed the empty-to-None collapse so an explicitly
loaded-but-empty roles list is preserved as [], matching _extract_role_names
behavior and the round-trip test expectation.
##########
superset/mcp_service/user/schemas.py:
##########
@@ -277,9 +305,17 @@ def serialize_user_object(
if include_sensitive and include_roles:
user_roles = getattr(user, "roles", None)
if user_roles is not None:
- try:
- roles = [r.name for r in user_roles if hasattr(r, "name")]
- except (AttributeError, DetachedInstanceError):
+ roles = []
+ for r in user_roles:
+ try:
+ if hasattr(r, "name") and isinstance(r.name, str):
+ roles.append(escape_llm_context_delimiters(r.name))
+ except (AttributeError, DetachedInstanceError):
+ logger.debug(
+ "Skipping role that raised exception in
serialize_user_object"
+ )
+ continue
+ if not roles:
roles = None
Review Comment:
Fixed in latest commit. Removed the empty-to-None collapse so an explicitly
loaded-but-empty roles list is preserved as [], matching _extract_role_names
behavior and the round-trip test expectation.
--
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]