From d728fa7aa6ff6033aa5c444b1f7f1b07b143a4be Mon Sep 17 00:00:00 2001 From: Sujan Adhikari <109404840+Sujanadh@users.noreply.github.com> Date: Tue, 2 Jan 2024 02:31:37 +0545 Subject: [PATCH] refactor: pydantic v2 deprecations (#1074) Co-authored-by: sujanadh --- src/backend/app/projects/project_schemas.py | 6 +++--- src/backend/app/tasks/tasks_schemas.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/backend/app/projects/project_schemas.py b/src/backend/app/projects/project_schemas.py index 8308444aa2..01f5a5d1a7 100644 --- a/src/backend/app/projects/project_schemas.py +++ b/src/backend/app/projects/project_schemas.py @@ -22,7 +22,7 @@ from typing import List, Optional from geojson_pydantic import Feature as GeojsonFeature -from pydantic import BaseModel, validator +from pydantic import BaseModel, field_validator from app.db import db_models from app.models.enums import ProjectPriority, ProjectStatus, TaskSplitType @@ -161,12 +161,12 @@ class ProjectDashboard(BaseModel): created: datetime last_active: Optional[str] = None - @validator("created", pre=False, always=True) + @field_validator("created", mode="before") def get_created(cls, value, values): date = value.strftime("%d %b %Y") return date - @validator("last_active", pre=False, always=True) + @field_validator("last_active", mode="before") def get_last_active(cls, value, values): if value is None: return None diff --git a/src/backend/app/tasks/tasks_schemas.py b/src/backend/app/tasks/tasks_schemas.py index 0036ce0520..20fa2d3ca3 100644 --- a/src/backend/app/tasks/tasks_schemas.py +++ b/src/backend/app/tasks/tasks_schemas.py @@ -24,7 +24,7 @@ from geojson_pydantic import Feature from loguru import logger as log -from pydantic import BaseModel, ConfigDict, Field, ValidationInfo, validator +from pydantic import BaseModel, ConfigDict, Field, ValidationInfo from pydantic.functional_validators import field_validator from app.db.postgis_utils import geometry_to_geojson, get_centroid @@ -71,7 +71,7 @@ class TaskBase(BaseModel): locked_by_username: Optional[str] = None task_history: Optional[List[TaskHistoryBase]] = None - @validator("task_status", pre=False, always=True) + @field_validator("task_status", mode="before") def get_enum_name(cls, value, values): if isinstance(value, int): try: