@@ -607,6 +607,14 @@ def get_media_profile_for_handle(
607607 return get_media_profile_for_object (db_handle , obj , args , locale = locale )
608608
609609
610+ def catch_handle_error (method , handle ):
611+ """Execute method on handle and return an empty dict on HandleError."""
612+ try :
613+ return method (handle )
614+ except HandleError :
615+ return {}
616+
617+
610618def get_extended_attributes (
611619 db_handle : DbReadBase , obj : GrampsObject , args : Optional [Dict ] = None
612620) -> Dict :
@@ -620,50 +628,55 @@ def get_extended_attributes(
620628 obj , "child_ref_list"
621629 ):
622630 result ["children" ] = [
623- db_handle .get_person_from_handle ( child_ref .ref )
631+ catch_handle_error ( db_handle .get_person_from_handle , child_ref .ref )
624632 for child_ref in obj .child_ref_list
625633 ]
626634 if (do_all or "citation_list" in args ["extend" ]) and hasattr (obj , "citation_list" ):
627635 result ["citations" ] = [
628- db_handle .get_citation_from_handle (handle ) for handle in obj .citation_list
636+ catch_handle_error (db_handle .get_citation_from_handle , handle )
637+ for handle in obj .citation_list
629638 ]
630639 if (do_all or "event_ref_list" in args ["extend" ]) and hasattr (
631640 obj , "event_ref_list"
632641 ):
633642 result ["events" ] = [
634- db_handle .get_event_from_handle ( event_ref .ref )
643+ catch_handle_error ( db_handle .get_event_from_handle , event_ref .ref )
635644 for event_ref in obj .event_ref_list
636645 ]
637646 if (do_all or "media_list" in args ["extend" ]) and hasattr (obj , "media_list" ):
638647 result ["media" ] = [
639- db_handle .get_media_from_handle ( media_ref .ref )
648+ catch_handle_error ( db_handle .get_media_from_handle , media_ref .ref )
640649 for media_ref in obj .media_list
641650 ]
642651 if (do_all or "note_list" in args ["extend" ]) and hasattr (obj , "note_list" ):
643652 result ["notes" ] = [
644- db_handle .get_note_from_handle (handle ) for handle in obj .note_list
653+ catch_handle_error (db_handle .get_note_from_handle , handle )
654+ for handle in obj .note_list
645655 ]
646656 if (do_all or "person_ref_list" in args ["extend" ]) and hasattr (
647657 obj , "person_ref_list"
648658 ):
649659 result ["people" ] = [
650- db_handle .get_person_from_handle ( person_ref .ref )
660+ catch_handle_error ( db_handle .get_person_from_handle , person_ref .ref )
651661 for person_ref in obj .person_ref_list
652662 ]
653663 if (do_all or "reporef_list" in args ["extend" ]) and hasattr (obj , "reporef_list" ):
654664 result ["repositories" ] = [
655- db_handle .get_repository_from_handle ( repo_ref .ref )
665+ catch_handle_error ( db_handle .get_repository_from_handle , repo_ref .ref )
656666 for repo_ref in obj .reporef_list
657667 ]
658668 if (do_all or "tag_list" in args ["extend" ]) and hasattr (obj , "tag_list" ):
659669 result ["tags" ] = [
660- db_handle .get_tag_from_handle (handle ) for handle in obj .tag_list
670+ catch_handle_error (db_handle .get_tag_from_handle , handle )
671+ for handle in obj .tag_list
661672 ]
662673 if (do_all or "backlinks" in args ["extend" ]) and hasattr (obj , "backlinks" ):
663674 result ["backlinks" ] = {}
664675 for class_name , backlinks in obj .backlinks .items ():
665676 result ["backlinks" ][class_name ] = [
666- db_handle .method ("get_%s_from_handle" , class_name .upper ())(handle )
677+ catch_handle_error (
678+ db_handle .method ("get_%s_from_handle" , class_name .upper ()), handle
679+ )
667680 for handle in backlinks
668681 ]
669682 return result
0 commit comments