@@ -407,9 +407,10 @@ async def search_wof(
407407 ancestor_ids = list (
408408 set (
409409 [
410- a [ "ancestor_id" ]
410+ a . get ( "ancestor_id" )
411411 for ancestors_list in ancestors_map .values ()
412412 for a in ancestors_list
413+ if a .get ("ancestor_id" ) is not None
413414 ]
414415 )
415416 )
@@ -425,7 +426,9 @@ async def search_wof(
425426 # Add names to ancestors
426427 for _wok_id , ancestors_list in ancestors_map .items ():
427428 for ancestor in ancestors_list :
428- ancestor ["name" ] = ancestor_names_map .get (ancestor ["ancestor_id" ])
429+ ancestor_id = ancestor .get ("ancestor_id" )
430+ if ancestor_id is not None :
431+ ancestor ["name" ] = ancestor_names_map .get (ancestor_id )
429432
430433 # Fetch GeoJSON for all results in batch
431434 geojson_map = {}
@@ -443,8 +446,8 @@ async def search_wof(
443446
444447 # Group by wok_id, keeping only the first (best) one
445448 for geojson_record in geojson_records :
446- wok_id = geojson_record [ "wok_id" ]
447- if wok_id not in geojson_map :
449+ wok_id = geojson_record . get ( "wok_id" )
450+ if wok_id is not None and wok_id not in geojson_map :
448451 geojson_map [wok_id ] = dict (geojson_record )
449452
450453 # Convert results to JSON:API format
@@ -484,7 +487,7 @@ async def search_wof(
484487 # Get GeoJSON for this place
485488 geojson_record = geojson_map .get (wok_id )
486489 geojson_data = None
487- if geojson_record :
490+ if geojson_record and "body" in geojson_record :
488491 try :
489492 geojson_data = json .loads (geojson_record ["body" ])
490493 except (json .JSONDecodeError , TypeError ):
0 commit comments