diff --git a/fastapi_auth_partner/routers/auth.py b/fastapi_auth_partner/routers/auth.py index 6be7fb41..d17ed995 100644 --- a/fastapi_auth_partner/routers/auth.py +++ b/fastapi_auth_partner/routers/auth.py @@ -43,7 +43,7 @@ def register( env["fastapi.auth.service"].sudo()._register_auth(endpoint.directory_id, data) ) partner_auth._set_auth_cookie(response) - return AuthPartnerResponse.model_validate(partner_auth) + return AuthPartnerResponse.from_auth_partner(partner_auth) @auth_router.post("/auth/login") @@ -57,7 +57,7 @@ def login( env["fastapi.auth.service"].sudo()._login(endpoint.directory_id, data) ) partner_auth._set_auth_cookie(response) - return AuthPartnerResponse.model_validate(partner_auth) + return AuthPartnerResponse.from_auth_partner(partner_auth) @auth_router.post("/auth/logout", status_code=205) @@ -91,7 +91,7 @@ def set_password( env["fastapi.auth.service"].sudo()._set_password(endpoint.directory_id, data) ) partner_auth._set_auth_cookie(response) - return AuthPartnerResponse.model_validate(partner_auth) + return AuthPartnerResponse.from_auth_partner(partner_auth) @auth_router.get("/auth/profile") @@ -103,7 +103,7 @@ def profile( partner_auth = partner.auth_partner_ids.filtered( lambda s: s.directory_id == endpoint.sudo().directory_id ) - return AuthPartnerResponse.model_validate(partner_auth) + return AuthPartnerResponse.from_auth_partner(partner_auth) class AuthService(models.AbstractModel): diff --git a/fastapi_auth_partner/schemas.py b/fastapi_auth_partner/schemas.py index 5a2cd3fd..de44c04e 100644 --- a/fastapi_auth_partner/schemas.py +++ b/fastapi_auth_partner/schemas.py @@ -3,8 +3,6 @@ from extendable_pydantic import StrictExtendableBaseModel -from pydantic import ConfigDict - class AuthLoginInput(StrictExtendableBaseModel): login: str @@ -28,4 +26,7 @@ class AuthSetPasswordInput(StrictExtendableBaseModel): class AuthPartnerResponse(StrictExtendableBaseModel): login: str - model_config = ConfigDict(from_attributes=True) + + @classmethod + def from_auth_partner(cls, odoo_rec): + return cls.model_construct(login=odoo_rec.login)