Fix type annotation for location_id; change from Optional[str] to Optional[int] for correct database mapping

This commit is contained in:
Yaro Kasear 2025-06-23 15:49:31 -05:00
parent 8162038f40
commit 04d262ae26
2 changed files with 5 additions and 4 deletions

View file

@ -407,22 +407,23 @@ def settings():
if mapper is not None:
db.session.flush()
mapper[clean] = new_obj.id
def resolve_id(raw_id, fallback_list, id_map, label):
try:
resolved_id = int(raw_id)
except (TypeError, ValueError):
raise ValueError(f"{label.title()} ID was not a valid integer: {raw_id}")
if resolved_id >= 0:
# Try to validate this ID by checking if it appears in the map values
if resolved_id in id_map.values():
return resolved_id
else:
raise ValueError(f"{label.title()} ID {resolved_id} not found in known {label}s.")
# It's a negative ID = created on frontend. Resolve from fallback list
index = abs(resolved_id + 1)
entry = None # Ensure entry is always defined
try:
entry = fallback_list[index]
key = entry["name"] if isinstance(entry, dict) else str(entry).strip()