Skip to content

Commit

Permalink
refactor: pydantic v2 deprecations (#1074)
Browse files Browse the repository at this point in the history
Co-authored-by: sujanadh <sujanadh07@gmail.com>
  • Loading branch information
Sujanadh and sujanadh authored Jan 1, 2024
1 parent 6a7da9a commit d728fa7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/backend/app/projects/project_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/backend/app/tasks/tasks_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit d728fa7

Please sign in to comment.