File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change 1616 status ,
1717)
1818from fastapi .responses import FileResponse
19+ from pydantic import TypeAdapter , ValidationError
1920from starlette .background import BackgroundTask
2021
2122from tekst import errors , tasks
@@ -269,6 +270,11 @@ async def _update_text_structure_task(
269270 updated_docs = []
270271 last_text_id = None
271272 all_locs_same_text = True
273+ label_field_adapter = TypeAdapter (LocationDocument .model_fields ["label" ].annotation )
274+ aliases_field_adapter = TypeAdapter (
275+ LocationDocument .model_fields ["aliases" ].annotation
276+ )
277+
272278 for loc in location_updates :
273279 try :
274280 doc_id = PydanticObjectId (loc ["id" ])
@@ -298,11 +304,12 @@ async def _update_text_structure_task(
298304 # modify label and aliases according to updates (and nothing else!)
299305 try :
300306 if "label" in loc :
307+ label_field_adapter .validate_python (loc ["label" ])
301308 loc_doc .label = loc ["label" ]
302309 if "aliases" in loc :
310+ aliases_field_adapter .validate_python (loc ["aliases" ])
303311 loc_doc .aliases = loc ["aliases" ]
304- LocationDocument .model_validate (loc_doc .model_dump ())
305- except Exception as e :
312+ except ValidationError as e :
306313 raise errors .update_values (
307314 exc = errors .E_422_UPLOAD_INVALID_DATA ,
308315 values = {"errors" : str (e )},
You can’t perform that action at this time.
0 commit comments