From 2f0496d0a3a31238cd545e536c6d864b79bcdd7c Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Sat, 6 Jun 2015 19:56:34 -0400 Subject: [PATCH] 8621: Recursion Filter error --- .../rules/person/_isdescendantfamilyof.py | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/gramps/gen/filters/rules/person/_isdescendantfamilyof.py b/gramps/gen/filters/rules/person/_isdescendantfamilyof.py index 0de35a0fc..e1c0ec9fc 100644 --- a/gramps/gen/filters/rules/person/_isdescendantfamilyof.py +++ b/gramps/gen/filters/rules/person/_isdescendantfamilyof.py @@ -78,22 +78,26 @@ class IsDescendantFamilyOf(Rule): return # Add self - self.matches.add(person.handle) + expand = [person] - 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 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) + while expand: + person = expand.pop(0) + if person is None: + continue + self.matches.add(person.handle) + 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: + expand.append(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) def exclude(self): # This removes root person and his/her spouses from the matches set