Skip to content

to fix: return types of whitelisted method #6

@harshtandiya

Description

@harshtandiya

If I don't do model_dump() then I get a list of the parameter, value tuples.

There should be a better way to handle this. Maybe a custom wrapper

See from CodeRabbit below

⚠️ Potential issue | 🟡 Minor

Fix return type annotation to match actual return value.

The function returns a list of dictionaries (via .model_dump() on each team), but the return type annotation specifies list[GetUserTeamsResponseSchema]. This mismatch can mislead type checkers and developers.

🔎 Proposed fix
 @frappe.whitelist()
-def get_user_teams() -> list[GetUserTeamsResponseSchema]:
+def get_user_teams() -> list[dict]:
     """
     Get the list of teams for the current user
     """
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

@frappe.whitelist()
def get_user_teams() -> list[dict]:
    """
    Get the list of teams for the current user
    """

    user = frappe.session.user

    if user == "Guest":
        return []

    teams = get_user_teams_utils(user)

    return [GetUserTeamsResponseSchema.model_validate(team).model_dump() for team in teams]
🤖 Prompt for AI Agents
In forms_pro/api/user.py around lines 48 to 61, the return type annotation
incorrectly declares list[GetUserTeamsResponseSchema] while the function
actually returns a list of dicts produced by .model_dump(); update the function
signature to reflect the actual return type (e.g., list[dict] or
list[Mapping[str, Any]]), or alternatively return the actual schema instances
(remove .model_dump()) to keep the current annotation—pick one approach and make
the signature and returned values consistent.

Originally posted by @coderabbitai[bot] in #5 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions