Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow empty task id in entity statuses for new geopoint #1822

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -418,7 +418,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