Fix type annotation for location_id; change from Optional[str] to Optional[int] for correct database mapping
This commit is contained in:
parent
8162038f40
commit
04d262ae26
2 changed files with 5 additions and 4 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue