From f1065bc2749c0fd82836254dc4fb6df321f82629 Mon Sep 17 00:00:00 2001 From: ribardej Date: Mon, 13 Oct 2025 13:50:59 +0200 Subject: [PATCH] feat(backend): update consistent Pydantic v2 use everywhere --- 7project/backend/app/schemas/category.py | 17 +++++------------ 7project/backend/app/schemas/transaction.py | 6 +++--- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/7project/backend/app/schemas/category.py b/7project/backend/app/schemas/category.py index f2df310..07fedaf 100644 --- a/7project/backend/app/schemas/category.py +++ b/7project/backend/app/schemas/category.py @@ -1,23 +1,16 @@ from typing import Optional -from pydantic import BaseModel -try: - # Pydantic v2 - from pydantic import ConfigDict # type: ignore - _HAS_V2 = True -except Exception: # pragma: no cover - _HAS_V2 = False +from pydantic import BaseModel, ConfigDict + class CategoryBase(BaseModel): name: str description: Optional[str] = None + class CategoryCreate(CategoryBase): pass + class CategoryRead(CategoryBase): id: int - if _HAS_V2: - model_config = ConfigDict(from_attributes=True) # type: ignore - else: # Pydantic v1 fallback - class Config: # type: ignore - orm_mode = True + model_config = ConfigDict(from_attributes=True) \ No newline at end of file diff --git a/7project/backend/app/schemas/transaction.py b/7project/backend/app/schemas/transaction.py index 2275dc0..9d82b4f 100644 --- a/7project/backend/app/schemas/transaction.py +++ b/7project/backend/app/schemas/transaction.py @@ -1,5 +1,6 @@ from typing import List, Optional -from pydantic import BaseModel, Field +from pydantic import BaseModel, Field, ConfigDict + class TransactionBase(BaseModel): amount: float = Field(..., gt=-1e18, lt=1e18) @@ -17,5 +18,4 @@ class TransactionRead(TransactionBase): id: int category_ids: List[int] = [] - class Config: - from_attributes = True + model_config = ConfigDict(from_attributes=True)