From e803926cce8f953fe9bbd998ad50c4e0c7fcb476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Sun, 29 Oct 2023 17:44:31 +0100 Subject: [PATCH] fastapi_auth_partner: migrate to pydantic 2 --- fastapi_auth_partner/routers/auth.py | 8 ++++---- fastapi_auth_partner/schemas.py | 21 ++++++++------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/fastapi_auth_partner/routers/auth.py b/fastapi_auth_partner/routers/auth.py index 4e2178c3..6be7fb41 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.from_orm(partner_auth) + return AuthPartnerResponse.model_validate(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.from_orm(partner_auth) + return AuthPartnerResponse.model_validate(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.from_orm(partner_auth) + return AuthPartnerResponse.model_validate(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.from_orm(partner_auth) + return AuthPartnerResponse.model_validate(partner_auth) class AuthService(models.AbstractModel): diff --git a/fastapi_auth_partner/schemas.py b/fastapi_auth_partner/schemas.py index a000ba8a..5a2cd3fd 100644 --- a/fastapi_auth_partner/schemas.py +++ b/fastapi_auth_partner/schemas.py @@ -1,36 +1,31 @@ # Copyright (c) Akretion 2020 # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) -from extendable_pydantic import ExtendableModelMeta +from extendable_pydantic import StrictExtendableBaseModel -from odoo.addons.pydantic import utils +from pydantic import ConfigDict -from pydantic import BaseModel - -class AuthLoginInput(BaseModel, metaclass=ExtendableModelMeta): +class AuthLoginInput(StrictExtendableBaseModel): login: str password: str -class AuthRegisterInput(BaseModel, metaclass=ExtendableModelMeta): +class AuthRegisterInput(StrictExtendableBaseModel): name: str login: str password: str -class AuthForgetPasswordInput(BaseModel, metaclass=ExtendableModelMeta): +class AuthForgetPasswordInput(StrictExtendableBaseModel): login: str -class AuthSetPasswordInput(BaseModel, metaclass=ExtendableModelMeta): +class AuthSetPasswordInput(StrictExtendableBaseModel): token: str password: str -class AuthPartnerResponse(BaseModel, metaclass=ExtendableModelMeta): +class AuthPartnerResponse(StrictExtendableBaseModel): login: str - - class Config: - orm_mode = True - getter_dict = utils.GenericOdooGetter + model_config = ConfigDict(from_attributes=True)