from gramps.gen.relationship import get_relationship_calculator
…
self.relationship = get_relationship_calculator()
…
=> self.relationship.get_relationship_distance_new(self.dbstate.db, default_person, person, only_birth=True) ...
also, get it by setting only_birth=False
Possible for the __apply_filter
method (line 1623)
Line 1623 (and following):
# Before
childrel = [
(ref.get_mother_relation(), ref.get_father_relation())
for ref in family.get_child_ref_list()
if ref.ref == person.handle
]
fhandle = family.father_handle
mhandle = family.mother_handle
for data in [
(fhandle, self.REL_FATHER, self.REL_FATHER_NOTBIRTH, childrel[0][1]),
(mhandle, self.REL_MOTHER, self.REL_MOTHER_NOTBIRTH, childrel[0][0]),
]:
# ...
Fix (add after the definition of childrel
):
childrel = [
(ref.get_mother_relation(), ref.get_father_relation())
for ref in family.get_child_ref_list()
if ref.ref == person.handle
]
# Add this check
if not childrel:
continue # Skip to the next family if childrel is empty
fhandle = family.father_handle
mhandle = family.mother_handle
for data in [
(fhandle, self.REL_FATHER, self.REL_FATHER_NOTBIRTH, childrel[0][1]),
(mhandle, self.REL_MOTHER, self.REL_MOTHER_NOTBIRTH, childrel[0][0]),
]:
# ...
Fix for the get_birth_parents
method (around line 1000)
Line 1000 (and following):
# Before
def get_birth_parents(self, db, person):
birthfather = None
birthmother = None
for fam in person.get_parent_family_handle_list():
family = db.get_family_from_handle(fam)
if not family:
continue
childrel = [
(ref.get_mother_relation(), ref.get_father_relation())
for ref in family.get_child_ref_list()
if ref.ref == person.handle
]
if not birthmother and childrel[0][0] == ChildRefType.BIRTH:
birthmother = family.get_mother_handle()
if not birthfather and childrel[0][1] == ChildRefType.BIRTH:
birthfather = family.get_father_handle()
if birthmother and birthfather:
break
return (birthmother, birthfather)
Fix (add after the definition of childrel
):
def get_birth_parents(self, db, person):
birthfather = None
birthmother = None
for fam in person.get_parent_family_handle_list():
family = db.get_family_from_handle(fam)
if not family:
continue
childrel = [
(ref.get_mother_relation(), ref.get_father_relation())
for ref in family.get_child_ref_list()
if ref.ref == person.handle
]
# Add this check
if not childrel:
continue # Skip to the next family if childrel is empty
if not birthmother and childrel[0][0] == ChildRefType.BIRTH:
birthmother = family.get_mother_handle()
if not birthfather and childrel[0][1] == ChildRefType.BIRTH:
birthfather = family.get_father_handle()
if birthmother and birthfather:
break
return (birthmother, birthfather)
Summary of Changes
-
Line 1623: Add a check for childrel
before accessing childrel[0]
.
-
Line 1000: Add the same check in get_birth_parents
.
These changes ensure the code will not crash if childrel
is empty, fixing the IndexError: list index out of range
error.
// AI // Question: Would you like me to help you test these fixes or explore other parts of the code for similar issues?