diff --git a/src/backend/app/tasks/tasks_schemas.py b/src/backend/app/tasks/tasks_schemas.py index bde911e32b..4cd8fe51e4 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 +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 @@ -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: