Skip to content

Commit

Permalink
fix(backend): allow empty task id in entity statuses for new geopoint (
Browse files Browse the repository at this point in the history
…#1822)

* fix: allow empty task-id in entity statuses

* fix: apply merge polygon function only if multipolygon

* fix: use field validator and convert str values to int
  • Loading branch information
Sujanadh authored and spwoodcock committed Oct 18, 2024
1 parent 29506dd commit 98827ba
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
5 changes: 0 additions & 5 deletions src/backend/app/central/central_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 23 additions & 1 deletion src/backend/app/central/central_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion src/backend/app/projects/project_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 98827ba

Please sign in to comment.