diff --git a/src/Filters/Rules/Person/_DeepRelationshipPathBetween.py b/src/Filters/Rules/Person/_DeepRelationshipPathBetween.py index 7d591d00a..8006afae0 100644 --- a/src/Filters/Rules/Person/_DeepRelationshipPathBetween.py +++ b/src/Filters/Rules/Person/_DeepRelationshipPathBetween.py @@ -75,7 +75,8 @@ def get_family_handle_people(db, exclude_handle, family_handle): possibly_add_handle(family.get_mother_handle()) for child_ref in family.get_child_ref_list(): - possibly_add_handle(child_ref.get_reference_handle()) + if child_ref: + possibly_add_handle(child_ref.get_reference_handle()) return people diff --git a/src/Filters/Rules/Person/_FamilyWithIncompleteEvent.py b/src/Filters/Rules/Person/_FamilyWithIncompleteEvent.py index cd3496e0f..259aa8762 100644 --- a/src/Filters/Rules/Person/_FamilyWithIncompleteEvent.py +++ b/src/Filters/Rules/Person/_FamilyWithIncompleteEvent.py @@ -48,11 +48,12 @@ class FamilyWithIncompleteEvent(Rule): def apply(self,db,person): for family_handle in person.get_family_handle_list(): family = db.get_family_from_handle(family_handle) - for event_ref in family.get_event_ref_list(): - if event_ref: - event = db.get_event_from_handle(event_ref.ref) - if not event.get_place_handle(): - return True - if not event.get_date_object(): - return True + if family: + for event_ref in family.get_event_ref_list(): + if event_ref: + event = db.get_event_from_handle(event_ref.ref) + if not event.get_place_handle(): + return True + if not event.get_date_object(): + return True return False diff --git a/src/Filters/Rules/Person/_HasBirth.py b/src/Filters/Rules/Person/_HasBirth.py index b1022ac74..aab112973 100644 --- a/src/Filters/Rules/Person/_HasBirth.py +++ b/src/Filters/Rules/Person/_HasBirth.py @@ -58,7 +58,9 @@ class HasBirth(Rule): def apply(self,db,person): for event_ref in person.get_event_ref_list(): - if event_ref.role != EventRoleType.PRIMARY: + if not event_ref: + continue + elif event_ref.role != EventRoleType.PRIMARY: # Only match primaries, no witnesses continue event = db.get_event_from_handle(event_ref.ref) diff --git a/src/Filters/Rules/Person/_HasCommonAncestorWith.py b/src/Filters/Rules/Person/_HasCommonAncestorWith.py index 3134b1b5f..ca4101168 100644 --- a/src/Filters/Rules/Person/_HasCommonAncestorWith.py +++ b/src/Filters/Rules/Person/_HasCommonAncestorWith.py @@ -68,14 +68,15 @@ class HasCommonAncestorWith(Rule): for fam_handle in person.get_parent_family_handle_list(): fam = db.get_family_from_handle(fam_handle) - for par_handle in (fam.get_father_handle(), fam.get_mother_handle()): - if par_handle: - par = db.get_person_from_handle(par_handle) - if par and par.handle not in self.ancestor_cache: - self.add_ancs(db, par) - if par: - self.ancestor_cache[person.handle].add(par) - self.ancestor_cache[person.handle] |= self.ancestor_cache[par.handle] + if fam: + for par_handle in (fam.get_father_handle(), fam.get_mother_handle()): + if par_handle: + par = db.get_person_from_handle(par_handle) + if par and par.handle not in self.ancestor_cache: + self.add_ancs(db, par) + if par: + self.ancestor_cache[person.handle].add(par) + self.ancestor_cache[person.handle] |= self.ancestor_cache[par.handle] def reset(self): self.ancestor_cache = {} diff --git a/src/Filters/Rules/Person/_HasDeath.py b/src/Filters/Rules/Person/_HasDeath.py index 458ad399b..36b19d270 100644 --- a/src/Filters/Rules/Person/_HasDeath.py +++ b/src/Filters/Rules/Person/_HasDeath.py @@ -58,7 +58,9 @@ class HasDeath(Rule): def apply(self,db,person): for event_ref in person.get_event_ref_list(): - if event_ref.role != EventRoleType.PRIMARY: + if not event_ref: + continue + elif event_ref.role != EventRoleType.PRIMARY: # Only match primaries, no witnesses continue event = db.get_event_from_handle(event_ref.ref) diff --git a/src/Filters/Rules/Person/_HasFamilyAttribute.py b/src/Filters/Rules/Person/_HasFamilyAttribute.py index 5033bc295..17de7b49c 100644 --- a/src/Filters/Rules/Person/_HasFamilyAttribute.py +++ b/src/Filters/Rules/Person/_HasFamilyAttribute.py @@ -53,10 +53,13 @@ class HasFamilyAttribute(Rule): return False for f_id in person.get_family_handle_list(): f = db.get_family_from_handle(f_id) + if not f: + continue for attr in f.get_attribute_list(): - name_match = self.list[0] == attr.get_type() - value_match = \ - attr.get_value().upper().find(self.list[1].upper()) != -1 - if name_match and value_match: - return True + if attr: + name_match = self.list[0] == attr.get_type() + value_match = \ + attr.get_value().upper().find(self.list[1].upper()) != -1 + if name_match and value_match: + return True return False diff --git a/src/Filters/Rules/Person/_HasFamilyEvent.py b/src/Filters/Rules/Person/_HasFamilyEvent.py index bab903968..393a1407d 100644 --- a/src/Filters/Rules/Person/_HasFamilyEvent.py +++ b/src/Filters/Rules/Person/_HasFamilyEvent.py @@ -64,6 +64,8 @@ class HasFamilyEvent(Rule): def apply(self,db,person): for f_id in person.get_family_handle_list(): f = db.get_family_from_handle(f_id) + if not f: + continue for event_ref in f.get_event_ref_list(): if not event_ref: continue diff --git a/src/Filters/Rules/Person/_HasRelationship.py b/src/Filters/Rules/Person/_HasRelationship.py index 98c0988d8..0d83b806e 100644 --- a/src/Filters/Rules/Person/_HasRelationship.py +++ b/src/Filters/Rules/Person/_HasRelationship.py @@ -61,9 +61,10 @@ class HasRelationship(Rule): # count children and look for a relationship type match for f_id in person.get_family_handle_list(): f = db.get_family_from_handle(f_id) - cnt = cnt + len(f.get_child_ref_list()) - if self.list[1] and specified_type == f.get_relationship(): - rel_type = 1 + if f: + cnt = cnt + len(f.get_child_ref_list()) + if self.list[1] and specified_type == f.get_relationship(): + rel_type = 1 # if number of relations specified if self.list[0]: diff --git a/src/Filters/Rules/Person/_HasTextMatchingSubstringOf.py b/src/Filters/Rules/Person/_HasTextMatchingSubstringOf.py index d14ce9b45..c09c677a4 100644 --- a/src/Filters/Rules/Person/_HasTextMatchingSubstringOf.py +++ b/src/Filters/Rules/Person/_HasTextMatchingSubstringOf.py @@ -171,7 +171,7 @@ class HasTextMatchingSubstringOf(Rule): self.repo_map.update( repo.handle for repo in self.db.iter_repositories() - if self.match_object(repo) + if repo and self.match_object(repo) ) diff --git a/src/Filters/Rules/Person/_HaveAltFamilies.py b/src/Filters/Rules/Person/_HaveAltFamilies.py index 21949292e..24bf8e016 100644 --- a/src/Filters/Rules/Person/_HaveAltFamilies.py +++ b/src/Filters/Rules/Person/_HaveAltFamilies.py @@ -48,9 +48,10 @@ class HaveAltFamilies(Rule): def apply(self,db,person): for fhandle in person.get_parent_family_handle_list(): family = db.get_family_from_handle(fhandle) - ref = [ ref for ref in family.get_child_ref_list() \ - if ref.ref == person.handle] - if ref[0].get_father_relation() == ChildRefType.ADOPTED \ - or ref[0].get_mother_relation() == ChildRefType.ADOPTED: - return True + if family: + ref = [ ref for ref in family.get_child_ref_list() \ + if ref.ref == person.handle] + if ref[0].get_father_relation() == ChildRefType.ADOPTED \ + or ref[0].get_mother_relation() == ChildRefType.ADOPTED: + return True return False diff --git a/src/Filters/Rules/Person/_HaveChildren.py b/src/Filters/Rules/Person/_HaveChildren.py index 03fc19965..65fb03c1c 100644 --- a/src/Filters/Rules/Person/_HaveChildren.py +++ b/src/Filters/Rules/Person/_HaveChildren.py @@ -47,4 +47,4 @@ class HaveChildren(Rule): def apply(self,db,person): for family_handle in person.get_family_handle_list(): family = db.get_family_from_handle(family_handle) - return len(family.get_child_ref_list()) > 0 + return family and len(family.get_child_ref_list()) > 0 diff --git a/src/Filters/Rules/Person/_IsChildOfFilterMatch.py b/src/Filters/Rules/Person/_IsChildOfFilterMatch.py index 6b0657581..90495ae06 100644 --- a/src/Filters/Rules/Person/_IsChildOfFilterMatch.py +++ b/src/Filters/Rules/Person/_IsChildOfFilterMatch.py @@ -69,5 +69,6 @@ class IsChildOfFilterMatch(MatchesFilter): return for fam_id in person.get_family_handle_list(): fam = self.db.get_family_from_handle(fam_id) - self.map.update(child_ref.ref - for child_ref in fam.get_child_ref_list()) + if fam: + self.map.update(child_ref.ref + for child_ref in fam.get_child_ref_list()) diff --git a/src/Filters/Rules/Person/_IsDescendantFamilyOf.py b/src/Filters/Rules/Person/_IsDescendantFamilyOf.py index db54f702d..424024e7b 100644 --- a/src/Filters/Rules/Person/_IsDescendantFamilyOf.py +++ b/src/Filters/Rules/Person/_IsDescendantFamilyOf.py @@ -83,17 +83,18 @@ class IsDescendantFamilyOf(Rule): for family_handle in person.get_family_handle_list(): family = self.db.get_family_from_handle(family_handle) + if family: + # Add every child recursively + for child_ref in family.get_child_ref_list(): + if child_ref: + self.add_matches(self.db.get_person_from_handle(child_ref.ref)) - # Add every child recursively - for child_ref in family.get_child_ref_list(): - self.add_matches(self.db.get_person_from_handle(child_ref.ref)) - - # Add spouse - if person.handle == family.get_father_handle(): - spouse_handle = family.get_mother_handle() - else: - spouse_handle = family.get_father_handle() - self.matches.add(spouse_handle) + # Add spouse + if person.handle == family.get_father_handle(): + spouse_handle = family.get_mother_handle() + else: + spouse_handle = family.get_father_handle() + self.matches.add(spouse_handle) def exclude(self): # This removes root person and his/her spouses from the matches set @@ -101,8 +102,9 @@ class IsDescendantFamilyOf(Rule): self.matches.remove(self.root_person.handle) for family_handle in self.root_person.get_family_handle_list(): family = self.db.get_family_from_handle(family_handle) - if self.root_person.handle == family.get_father_handle(): - spouse_handle = family.get_mother_handle() - else: - spouse_handle = family.get_father_handle() - self.matches.remove(spouse_handle) + if family: + if self.root_person.handle == family.get_father_handle(): + spouse_handle = family.get_mother_handle() + else: + spouse_handle = family.get_father_handle() + self.matches.remove(spouse_handle) diff --git a/src/Filters/Rules/Person/_IsLessThanNthGenerationDescendantOf.py b/src/Filters/Rules/Person/_IsLessThanNthGenerationDescendantOf.py index f7c4fc101..f3e51a4b7 100644 --- a/src/Filters/Rules/Person/_IsLessThanNthGenerationDescendantOf.py +++ b/src/Filters/Rules/Person/_IsLessThanNthGenerationDescendantOf.py @@ -75,6 +75,7 @@ class IsLessThanNthGenerationDescendantOf(Rule): for fam_id in person.get_family_handle_list(): fam = self.db.get_family_from_handle(fam_id) - for child_ref in fam.get_child_ref_list(): - self.init_list( - self.db.get_person_from_handle(child_ref.ref), gen+1) + if fam: + for child_ref in fam.get_child_ref_list(): + self.init_list( + self.db.get_person_from_handle(child_ref.ref), gen+1) diff --git a/src/Filters/Rules/Person/_IsMoreThanNthGenerationDescendantOf.py b/src/Filters/Rules/Person/_IsMoreThanNthGenerationDescendantOf.py index 399d3733d..d78372ab8 100644 --- a/src/Filters/Rules/Person/_IsMoreThanNthGenerationDescendantOf.py +++ b/src/Filters/Rules/Person/_IsMoreThanNthGenerationDescendantOf.py @@ -73,6 +73,7 @@ class IsMoreThanNthGenerationDescendantOf(Rule): for fam_id in person.get_family_handle_list(): fam = self.db.get_family_from_handle(fam_id) - for child_ref in fam.get_child_ref_list(): - self.init_list( - self.db.get_person_from_handle(child_ref.ref), gen+1) + if fam: + for child_ref in fam.get_child_ref_list(): + self.init_list( + self.db.get_person_from_handle(child_ref.ref), gen+1) diff --git a/src/Filters/Rules/Person/_IsParentOfFilterMatch.py b/src/Filters/Rules/Person/_IsParentOfFilterMatch.py index c9f64cbe2..5e092f8ef 100644 --- a/src/Filters/Rules/Person/_IsParentOfFilterMatch.py +++ b/src/Filters/Rules/Person/_IsParentOfFilterMatch.py @@ -67,6 +67,9 @@ class IsParentOfFilterMatch(MatchesFilter): def init_list(self,person): for fam_id in person.get_parent_family_handle_list(): fam = self.db.get_family_from_handle(fam_id) - self.map.update(parent_id - for parent_id in [fam.get_father_handle(), fam.get_mother_handle()] - if parent_id) + if fam: + self.map.update(parent_id + for parent_id in [fam.get_father_handle(), + fam.get_mother_handle()] + if parent_id) + diff --git a/src/Filters/Rules/Person/_IsSiblingOfFilterMatch.py b/src/Filters/Rules/Person/_IsSiblingOfFilterMatch.py index 20df7079e..dc66dec07 100644 --- a/src/Filters/Rules/Person/_IsSiblingOfFilterMatch.py +++ b/src/Filters/Rules/Person/_IsSiblingOfFilterMatch.py @@ -71,4 +71,4 @@ class IsSiblingOfFilterMatch(MatchesFilter): if fam: self.map.update(child_ref.ref for child_ref in fam.get_child_ref_list() - if child_ref.ref != person.handle) + if child_ref and child_ref.ref != person.handle) diff --git a/src/Filters/Rules/Person/_IsSpouseOfFilterMatch.py b/src/Filters/Rules/Person/_IsSpouseOfFilterMatch.py index c0ddd865a..783d1017a 100644 --- a/src/Filters/Rules/Person/_IsSpouseOfFilterMatch.py +++ b/src/Filters/Rules/Person/_IsSpouseOfFilterMatch.py @@ -55,11 +55,13 @@ class IsSpouseOfFilterMatch(MatchesFilter): def apply(self,db,person): for family_handle in person.get_family_handle_list (): family = db.get_family_from_handle(family_handle) - for spouse_id in [family.get_father_handle (), family.get_mother_handle ()]: - if not spouse_id: - continue - if spouse_id == person.handle: - continue - if self.filt.apply (db, db.get_person_from_handle( spouse_id)): - return True + if family: + for spouse_id in [family.get_father_handle(), + family.get_mother_handle()]: + if not spouse_id: + continue + if spouse_id == person.handle: + continue + if self.filt.apply (db, db.get_person_from_handle( spouse_id)): + return True return False diff --git a/src/Filters/Rules/Person/_IsWitness.py b/src/Filters/Rules/Person/_IsWitness.py index 73d76d632..7d505531d 100644 --- a/src/Filters/Rules/Person/_IsWitness.py +++ b/src/Filters/Rules/Person/_IsWitness.py @@ -48,7 +48,7 @@ class IsWitness(Rule): def apply(self,db,person): for event_ref in person.event_ref_list: - if event_ref.role == EventRoleType.WITNESS: + if event_ref and event_ref.role == EventRoleType.WITNESS: # This is the witness. # If event type was given, then check it. if self.list[0]: diff --git a/src/Filters/Rules/Person/_MissingParent.py b/src/Filters/Rules/Person/_MissingParent.py index 23de2b2ec..e2f25b9f8 100644 --- a/src/Filters/Rules/Person/_MissingParent.py +++ b/src/Filters/Rules/Person/_MissingParent.py @@ -53,10 +53,11 @@ class MissingParent(Rule): return True for family_handle in person.get_parent_family_handle_list(): family = db.get_family_from_handle(family_handle) - father_handle = family.get_father_handle() - mother_handle = family.get_mother_handle() - if not father_handle: - return True - if not mother_handle: - return True + if family: + father_handle = family.get_father_handle() + mother_handle = family.get_mother_handle() + if not father_handle: + return True + if not mother_handle: + return True return False