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,13 +63,20 @@ 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
expand = [start]
relatives = {}
while expand:
person = expand.pop()
# Add the relative to the list # Add the relative to the list
self.relatives.append(person.handle) if person is None or (person.handle in relatives):
continue
relatives[person.handle] = True
for family_handle in person.get_parent_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)
@ -77,10 +84,10 @@ class IsRelatedWith(Rule):
# Check Parents # 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 Sibilings # 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(): for family_handle in person.get_family_handle_list():
family = self.db.get_family_from_handle(family_handle) family = self.db.get_family_from_handle(family_handle)
@ -88,9 +95,10 @@ class IsRelatedWith(Rule):
# Check Spouse # Check Spouse
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 Children
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))
self.relatives = list(relatives.keys())
return return