codeant-ai-for-open-source[bot] commented on code in PR #40746:
URL: https://github.com/apache/superset/pull/40746#discussion_r3395872050
##########
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:
Review Comment:
**Suggestion:** Add an explicit type hint for the `cls` parameter in the new
validator method so all parameters in newly added method signatures are fully
typed. [custom_rule]
**Severity Level:** Minor ⚠️
<details>
<summary><b>Why it matters? 🤔 </b></summary>
This is a newly added method, and its signature omits a type hint for `cls`.
The custom rule requires new Python functions and methods to be fully typed, so
this is a real violation.
</details>
[Fix in
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=ee5b9b0bee474bed9bf526510842936a&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=ee5b9b0bee474bed9bf526510842936a&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/user/schemas.py
**Line:** 113:113
**Comment:**
*Custom Rule: Add an explicit type hint for the `cls` parameter in the
new validator method so all parameters in newly added method signatures are
fully typed.
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%2F40746&comment_hash=d996133bc1785da2b6f607eef752d12bc3b014d7ea1bc3da930fbd240fc16def&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40746&comment_hash=d996133bc1785da2b6f607eef752d12bc3b014d7ea1bc3da930fbd240fc16def&reaction=dislike'>👎</a>
##########
tests/unit_tests/mcp_service/user/test_schemas.py:
##########
@@ -0,0 +1,106 @@
+# 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.
+
+"""Unit tests for user-related MCP schemas."""
+
+from unittest.mock import MagicMock
+
+import pytest
+from pydantic import ValidationError
+from sqlalchemy.orm.exc import DetachedInstanceError
+
+from superset.mcp_service.user.schemas import UserInfo, serialize_user_object
+
+
+def test_user_info_rejects_bare_string_for_roles() -> None:
+ """A plain string must not be silently split into individual characters."""
+ with pytest.raises(ValidationError):
+ UserInfo(roles="Admin")
+
+
+def test_user_info_preserves_empty_roles_list() -> None:
+ """Empty roles should remain [] so callers can distinguish it from None."""
+ info = UserInfo(roles=[])
+ assert info.roles == []
+
+
+def test_user_info_coerces_role_objects_to_names() -> None:
+ """Role-like ORM objects must be converted to their .name strings."""
+ role_admin = MagicMock()
+ role_admin.name = "Admin"
+ role_alpha = MagicMock()
+ role_alpha.name = "Alpha"
+
+ info = UserInfo(roles=[role_admin, role_alpha])
+
+ assert info.roles == ["Admin", "Alpha"]
+
+
+def test_user_info_ignores_role_with_detached_instance() -> None:
+ """Detached ORM roles must not blow up serialization."""
+ role_good = MagicMock()
+ role_good.name = "Admin"
+
+ class DetachedRole:
Review Comment:
**Suggestion:** Add an inline docstring to the newly introduced class so the
class-level behavior is documented. [custom_rule]
**Severity Level:** Minor ⚠️
<details>
<summary><b>Why it matters? 🤔 </b></summary>
The class is newly introduced in the changed file and has no docstring. This
matches the custom rule requiring newly added Python classes to include inline
docstrings.
</details>
[Fix in
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=7134e1d1dba44a8e82a4990282caabb2&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=7134e1d1dba44a8e82a4990282caabb2&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:** tests/unit_tests/mcp_service/user/test_schemas.py
**Line:** 58:58
**Comment:**
*Custom Rule: Add an inline docstring to the newly introduced class so
the class-level behavior is documented.
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%2F40746&comment_hash=cdcbc99b53823d19b53c4d89ce7261c9467e129bd75e840d7538b3f1e7ef9b80&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40746&comment_hash=cdcbc99b53823d19b53c4d89ce7261c9467e129bd75e840d7538b3f1e7ef9b80&reaction=dislike'>👎</a>
##########
tests/unit_tests/mcp_service/user/test_schemas.py:
##########
@@ -0,0 +1,106 @@
+# 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.
+
+"""Unit tests for user-related MCP schemas."""
+
+from unittest.mock import MagicMock
+
+import pytest
+from pydantic import ValidationError
+from sqlalchemy.orm.exc import DetachedInstanceError
+
+from superset.mcp_service.user.schemas import UserInfo, serialize_user_object
+
+
+def test_user_info_rejects_bare_string_for_roles() -> None:
+ """A plain string must not be silently split into individual characters."""
+ with pytest.raises(ValidationError):
+ UserInfo(roles="Admin")
+
+
+def test_user_info_preserves_empty_roles_list() -> None:
+ """Empty roles should remain [] so callers can distinguish it from None."""
+ info = UserInfo(roles=[])
+ assert info.roles == []
+
+
+def test_user_info_coerces_role_objects_to_names() -> None:
+ """Role-like ORM objects must be converted to their .name strings."""
+ role_admin = MagicMock()
+ role_admin.name = "Admin"
+ role_alpha = MagicMock()
+ role_alpha.name = "Alpha"
+
+ info = UserInfo(roles=[role_admin, role_alpha])
+
+ assert info.roles == ["Admin", "Alpha"]
+
+
+def test_user_info_ignores_role_with_detached_instance() -> None:
+ """Detached ORM roles must not blow up serialization."""
+ role_good = MagicMock()
+ role_good.name = "Admin"
+
+ class DetachedRole:
+ @property
+ def name(self):
Review Comment:
**Suggestion:** Add a return type annotation to this new property method so
the method signature is fully typed. [custom_rule]
**Severity Level:** Minor ⚠️
<details>
<summary><b>Why it matters? 🤔 </b></summary>
The newly added property method omits a return type annotation. Since the
surrounding code is newly added, the custom rule requires new Python methods to
be fully typed, so this is a real violation.
</details>
[Fix in
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=05b5750f33c0434ab9354fafe95b28a5&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=05b5750f33c0434ab9354fafe95b28a5&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:** tests/unit_tests/mcp_service/user/test_schemas.py
**Line:** 59:60
**Comment:**
*Custom Rule: Add a return type annotation to this new property method
so the method signature is fully typed.
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%2F40746&comment_hash=699d4aec6284fce2add806ea82b81e05dbd0cb80bdf44a6c80da265379052aab&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40746&comment_hash=699d4aec6284fce2add806ea82b81e05dbd0cb80bdf44a6c80da265379052aab&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]