Skip to content

Commit

Permalink
fix: serialize task status as string (#1031)
Browse files Browse the repository at this point in the history
* fix: returned task status as string

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: sujanadh <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 6, 2023
1 parent d7351c7 commit 642dcf3
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion 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
from pydantic import BaseModel, ConfigDict, Field, ValidationInfo, validator
from pydantic.functional_validators import field_validator

from app.db.postgis_utils import geometry_to_geojson, get_centroid
Expand Down Expand Up @@ -70,6 +70,17 @@ class TaskBase(BaseModel):
locked_by_username: Optional[str] = None
task_history: Optional[List[TaskHistoryBase]] = None

@validator("task_status", pre=False, always=True)
def get_enum_name(cls, value, values):
if isinstance(value, int):
try:
return TaskStatus(value).name
except ValueError as e:
raise ValueError(
f"Invalid integer value for task_status: {value}"
) from e
return value

@field_validator("outline_geojson", mode="before")
@classmethod
def get_geojson_from_outline(cls, v: Any, info: ValidationInfo) -> str:
Expand Down

0 comments on commit 642dcf3

Please sign in to comment.