8564: Recursion error when filtering for relatives

This commit is contained in:
Doug Blank 2015-05-15 23:30:31 -04:00
parent 612c4665ae
commit 9f8ffc5226

View File

@ -63,34 +63,42 @@ class IsRelatedWith(Rule):
return person.handle in self.relatives return person.handle in self.relatives
def add_relative(self, person): def add_relative(self, start):
"""Recursive function that scans relatives and add them to self.relatives""" """Non-recursive function that scans relatives and add them to self.relatives"""
if not(person) or person.handle in self.relatives: if not(start):
return return
# Add the relative to the list expand = [start]
self.relatives.append(person.handle) relatives = {}
for family_handle in person.get_parent_family_handle_list(): while expand:
family = self.db.get_family_from_handle(family_handle) person = expand.pop()
if family: # Add the relative to the list
# Check Parents if person is None or (person.handle in relatives):
for parent_handle in (family.get_father_handle(), family.get_mother_handle()): continue
if parent_handle: relatives[person.handle] = True
self.add_relative(self.db.get_person_from_handle(parent_handle))
# Check Sibilings
for child_ref in family.get_child_ref_list():
self.add_relative(self.db.get_person_from_handle(child_ref.ref))
for family_handle in person.get_family_handle_list(): for family_handle in person.get_parent_family_handle_list():
family = self.db.get_family_from_handle(family_handle) family = self.db.get_family_from_handle(family_handle)
if family: if family:
# Check Spouse # Check Parents
for parent_handle in (family.get_father_handle(), family.get_mother_handle()): for parent_handle in (family.get_father_handle(), family.get_mother_handle()):
if parent_handle: if parent_handle:
self.add_relative(self.db.get_person_from_handle(parent_handle)) expand.append(self.db.get_person_from_handle(parent_handle))
# Check Children # Check Sibilings
for child_ref in family.get_child_ref_list(): for child_ref in family.get_child_ref_list():
self.add_relative(self.db.get_person_from_handle(child_ref.ref)) expand.append(self.db.get_person_from_handle(child_ref.ref))
for family_handle in person.get_family_handle_list():
family = self.db.get_family_from_handle(family_handle)
if family:
# Check Spouse
for parent_handle in (family.get_father_handle(), family.get_mother_handle()):
if parent_handle:
expand.append(self.db.get_person_from_handle(parent_handle))
# Check Children
for child_ref in family.get_child_ref_list():
expand.append(self.db.get_person_from_handle(child_ref.ref))
self.relatives = list(relatives.keys())
return return