diff --git a/src/backend/app/central/central_crud.py b/src/backend/app/central/central_crud.py index 22945aa9ed..6f2447c367 100644 --- a/src/backend/app/central/central_crud.py +++ b/src/backend/app/central/central_crud.py @@ -703,11 +703,6 @@ async def get_entities_data( # Rename '__id' to 'id' flattened_dict["id"] = flattened_dict.pop("__id") - # convert empty str osm_id to None - # when new entities are created osm_id will be empty - if flattened_dict.get("osm_id", "") == "": - flattened_dict["osm_id"] = None - all_entities.append(flattened_dict) return all_entities diff --git a/src/backend/app/central/central_schemas.py b/src/backend/app/central/central_schemas.py index c67e526cf4..edb7fc819d 100644 --- a/src/backend/app/central/central_schemas.py +++ b/src/backend/app/central/central_schemas.py @@ -140,12 +140,34 @@ class EntityOsmID(BaseModel): id: str osm_id: Optional[int] = None + @field_validator("osm_id", mode="before") + @classmethod + def convert_osm_id(cls, value): + """Set osm_id to None if empty or invalid.""" + if value in ("", " "): # Treat empty strings as None + return None + try: + return int(value) # Convert to integer if possible + except ValueError: + return value + class EntityTaskID(BaseModel): """Map of Entity UUID to FMTM Task ID.""" id: str - task_id: int + task_id: Optional[int] = None + + @field_validator("task_id", mode="before") + @classmethod + def convert_task_id(cls, value): + """Set task_id to None if empty or invalid.""" + if value in ("", " "): # Treat empty strings as None + return None + try: + return int(value) # Convert to integer if possible + except ValueError: + return value class EntityMappingStatus(EntityOsmID, EntityTaskID): diff --git a/src/backend/app/projects/project_crud.py b/src/backend/app/projects/project_crud.py index 1759cff1b3..f8b715f087 100644 --- a/src/backend/app/projects/project_crud.py +++ b/src/backend/app/projects/project_crud.py @@ -444,7 +444,8 @@ async def preview_split_by_square( Use a lambda function to remove the "z" dimension from each coordinate in the feature's geometry. """ - boundary = merge_polygons(boundary) + if len(boundary["features"]) == 0: + boundary = merge_polygons(boundary) return await run_in_threadpool( lambda: split_by_square(