Merge pull request #235 from prculley/9682CandR
bug 9682 fix Check & repair so it won't crash with bad 'get_from_handle'
This commit is contained in:
commit
939a4ae669
@ -71,6 +71,7 @@ from gramps.gui.plug import tool
|
|||||||
from gramps.gui.dialog import OkDialog, MissingMediaDialog
|
from gramps.gui.dialog import OkDialog, MissingMediaDialog
|
||||||
from gramps.gen.display.name import displayer as _nd
|
from gramps.gen.display.name import displayer as _nd
|
||||||
from gramps.gui.glade import Glade
|
from gramps.gui.glade import Glade
|
||||||
|
from gramps.gen.errors import HandleError
|
||||||
|
|
||||||
# table for handling control chars in notes.
|
# table for handling control chars in notes.
|
||||||
# All except 09, 0A, 0D are replaced with space.
|
# All except 09, 0A, 0D are replaced with space.
|
||||||
@ -425,8 +426,9 @@ class CheckIntegrity:
|
|||||||
father_handle = family.get_father_handle()
|
father_handle = family.get_father_handle()
|
||||||
mother_handle = family.get_mother_handle()
|
mother_handle = family.get_mother_handle()
|
||||||
if father_handle:
|
if father_handle:
|
||||||
|
try:
|
||||||
father = self.db.get_person_from_handle(father_handle)
|
father = self.db.get_person_from_handle(father_handle)
|
||||||
if not father:
|
except HandleError:
|
||||||
# The person referenced by the father handle does not exist
|
# The person referenced by the father handle does not exist
|
||||||
# in the database
|
# in the database
|
||||||
# This is tested by TestcaseGenerator where the mother is
|
# This is tested by TestcaseGenerator where the mother is
|
||||||
@ -440,8 +442,9 @@ class CheckIntegrity:
|
|||||||
'hand' : father_handle})
|
'hand' : father_handle})
|
||||||
father_handle = None
|
father_handle = None
|
||||||
if mother_handle:
|
if mother_handle:
|
||||||
|
try:
|
||||||
mother = self.db.get_person_from_handle(mother_handle)
|
mother = self.db.get_person_from_handle(mother_handle)
|
||||||
if not mother:
|
except HandleError:
|
||||||
# The person referenced by the mother handle does not exist
|
# The person referenced by the mother handle does not exist
|
||||||
# in the database
|
# in the database
|
||||||
# This is tested by TestcaseGenerator where the mother is
|
# This is tested by TestcaseGenerator where the mother is
|
||||||
@ -483,8 +486,21 @@ class CheckIntegrity:
|
|||||||
|
|
||||||
for child_ref in family.get_child_ref_list():
|
for child_ref in family.get_child_ref_list():
|
||||||
child_handle = child_ref.ref
|
child_handle = child_ref.ref
|
||||||
|
try:
|
||||||
child = self.db.get_person_from_handle(child_handle)
|
child = self.db.get_person_from_handle(child_handle)
|
||||||
if child:
|
except HandleError:
|
||||||
|
# The person referenced by the child handle
|
||||||
|
# does not exist in the database
|
||||||
|
# This is tested by TestcaseGenerator where the father
|
||||||
|
# is "Broken20"
|
||||||
|
logging.warning(" FAIL: family '%(fam_gid)s' child "
|
||||||
|
"'%(hand)s' does not exist in the database" %
|
||||||
|
{'fam_gid' : family.gramps_id,
|
||||||
|
'hand' : child_handle})
|
||||||
|
family.remove_child_ref(child_ref)
|
||||||
|
self.db.commit_family(family, self.trans)
|
||||||
|
self.broken_links.append((child_handle, family_handle))
|
||||||
|
else:
|
||||||
if child_handle in [father_handle, mother_handle]:
|
if child_handle in [father_handle, mother_handle]:
|
||||||
# The child is one of the parents: impossible Remove
|
# The child is one of the parents: impossible Remove
|
||||||
# such child from the family
|
# such child from the family
|
||||||
@ -513,18 +529,6 @@ class CheckIntegrity:
|
|||||||
'child_gid' : child.gramps_id})
|
'child_gid' : child.gramps_id})
|
||||||
child.add_parent_family_handle(family_handle)
|
child.add_parent_family_handle(family_handle)
|
||||||
self.db.commit_person(child, self.trans)
|
self.db.commit_person(child, self.trans)
|
||||||
else:
|
|
||||||
# The person referenced by the child handle
|
|
||||||
# does not exist in the database
|
|
||||||
# This is tested by TestcaseGenerator where the father
|
|
||||||
# is "Broken20"
|
|
||||||
logging.warning(" FAIL: family '%(fam_gid)s' child "
|
|
||||||
"'%(hand)s' does not exist in the database" %
|
|
||||||
{'fam_gid' : family.gramps_id,
|
|
||||||
'hand' : child_handle})
|
|
||||||
family.remove_child_ref(child_ref)
|
|
||||||
self.db.commit_family(family, self.trans)
|
|
||||||
self.broken_links.append((child_handle, family_handle))
|
|
||||||
|
|
||||||
new_ref_list = []
|
new_ref_list = []
|
||||||
new_ref_handles = []
|
new_ref_handles = []
|
||||||
@ -555,8 +559,9 @@ class CheckIntegrity:
|
|||||||
self.db.commit_person(person, self.trans)
|
self.db.commit_person(person, self.trans)
|
||||||
|
|
||||||
for par_family_handle in person.get_parent_family_handle_list():
|
for par_family_handle in person.get_parent_family_handle_list():
|
||||||
|
try:
|
||||||
family = self.db.get_family_from_handle(par_family_handle)
|
family = self.db.get_family_from_handle(par_family_handle)
|
||||||
if not family:
|
except HandleError:
|
||||||
person.remove_parent_family_handle(par_family_handle)
|
person.remove_parent_family_handle(par_family_handle)
|
||||||
self.db.commit_person(person, self.trans)
|
self.db.commit_person(person, self.trans)
|
||||||
continue
|
continue
|
||||||
@ -577,8 +582,9 @@ class CheckIntegrity:
|
|||||||
self.db.commit_person(person, self.trans)
|
self.db.commit_person(person, self.trans)
|
||||||
self.broken_links.append((person_handle, family_handle))
|
self.broken_links.append((person_handle, family_handle))
|
||||||
for family_handle in person.get_family_handle_list():
|
for family_handle in person.get_family_handle_list():
|
||||||
|
try:
|
||||||
family = self.db.get_family_from_handle(family_handle)
|
family = self.db.get_family_from_handle(family_handle)
|
||||||
if not family:
|
except HandleError:
|
||||||
# The referenced family does not exist in database
|
# The referenced family does not exist in database
|
||||||
# This is tested by TestcaseGenerator where the father
|
# This is tested by TestcaseGenerator where the father
|
||||||
# is "Broken20"
|
# is "Broken20"
|
||||||
@ -1008,8 +1014,9 @@ class CheckIntegrity:
|
|||||||
none_handle = True
|
none_handle = True
|
||||||
birth_ref.ref = create_id()
|
birth_ref.ref = create_id()
|
||||||
birth_handle = birth_ref.ref
|
birth_handle = birth_ref.ref
|
||||||
|
try:
|
||||||
birth = self.db.get_event_from_handle(birth_handle)
|
birth = self.db.get_event_from_handle(birth_handle)
|
||||||
if not birth:
|
except HandleError:
|
||||||
# The birth event referenced by the birth handle
|
# The birth event referenced by the birth handle
|
||||||
# does not exist in the database
|
# does not exist in the database
|
||||||
# This is tested by TestcaseGenerator person "Broken11"
|
# This is tested by TestcaseGenerator person "Broken11"
|
||||||
@ -1046,8 +1053,9 @@ class CheckIntegrity:
|
|||||||
none_handle = True
|
none_handle = True
|
||||||
death_ref.ref = create_id()
|
death_ref.ref = create_id()
|
||||||
death_handle = death_ref.ref
|
death_handle = death_ref.ref
|
||||||
|
try:
|
||||||
death = self.db.get_event_from_handle(death_handle)
|
death = self.db.get_event_from_handle(death_handle)
|
||||||
if not death:
|
except HandleError:
|
||||||
# The death event referenced by the death handle
|
# The death event referenced by the death handle
|
||||||
# does not exist in the database
|
# does not exist in the database
|
||||||
# This is tested by TestcaseGenerator person "Broken12"
|
# This is tested by TestcaseGenerator person "Broken12"
|
||||||
@ -1085,8 +1093,9 @@ class CheckIntegrity:
|
|||||||
none_handle = True
|
none_handle = True
|
||||||
event_ref.ref = create_id()
|
event_ref.ref = create_id()
|
||||||
event_handle = event_ref.ref
|
event_handle = event_ref.ref
|
||||||
|
try:
|
||||||
event = self.db.get_event_from_handle(event_handle)
|
event = self.db.get_event_from_handle(event_handle)
|
||||||
if not event:
|
except HandleError:
|
||||||
# The event referenced by the person
|
# The event referenced by the person
|
||||||
# does not exist in the database
|
# does not exist in the database
|
||||||
#TODO: There is no better way?
|
#TODO: There is no better way?
|
||||||
@ -1126,8 +1135,9 @@ class CheckIntegrity:
|
|||||||
none_handle = True
|
none_handle = True
|
||||||
event_ref.ref = create_id()
|
event_ref.ref = create_id()
|
||||||
event_handle = event_ref.ref
|
event_handle = event_ref.ref
|
||||||
|
try:
|
||||||
event = self.db.get_event_from_handle(event_handle)
|
event = self.db.get_event_from_handle(event_handle)
|
||||||
if not event:
|
except HandleError:
|
||||||
# The event referenced by the family
|
# The event referenced by the family
|
||||||
# does not exist in the database
|
# does not exist in the database
|
||||||
logging.warning(' FAIL: the family "%(gid)s" refers '
|
logging.warning(' FAIL: the family "%(gid)s" refers '
|
||||||
@ -1171,8 +1181,9 @@ class CheckIntegrity:
|
|||||||
if pref.ref is None:
|
if pref.ref is None:
|
||||||
none_handle = True
|
none_handle = True
|
||||||
pref.ref = create_id()
|
pref.ref = create_id()
|
||||||
|
try:
|
||||||
p = self.db.get_person_from_handle( pref.ref)
|
p = self.db.get_person_from_handle( pref.ref)
|
||||||
if not p:
|
except HandleError:
|
||||||
# The referenced person does not exist in the database
|
# The referenced person does not exist in the database
|
||||||
make_unknown(pref.ref, self.explanation.handle,
|
make_unknown(pref.ref, self.explanation.handle,
|
||||||
self.class_person, self.commit_person, self.trans)
|
self.class_person, self.commit_person, self.trans)
|
||||||
@ -1198,8 +1209,9 @@ class CheckIntegrity:
|
|||||||
for ordinance in person.get_lds_ord_list():
|
for ordinance in person.get_lds_ord_list():
|
||||||
family_handle = ordinance.get_family_handle()
|
family_handle = ordinance.get_family_handle()
|
||||||
if family_handle:
|
if family_handle:
|
||||||
|
try:
|
||||||
family = self.db.get_family_from_handle(family_handle)
|
family = self.db.get_family_from_handle(family_handle)
|
||||||
if not family:
|
except HandleError:
|
||||||
# The referenced family does not exist in the database
|
# The referenced family does not exist in the database
|
||||||
make_unknown(family_handle,
|
make_unknown(family_handle,
|
||||||
self.explanation.handle, self.class_family,
|
self.explanation.handle, self.class_family,
|
||||||
@ -1227,8 +1239,9 @@ class CheckIntegrity:
|
|||||||
if reporef.ref is None:
|
if reporef.ref is None:
|
||||||
none_handle = True
|
none_handle = True
|
||||||
reporef.ref = create_id()
|
reporef.ref = create_id()
|
||||||
|
try:
|
||||||
r = self.db.get_repository_from_handle(reporef.ref)
|
r = self.db.get_repository_from_handle(reporef.ref)
|
||||||
if not r:
|
except HandleError:
|
||||||
# The referenced repository does not exist in the database
|
# The referenced repository does not exist in the database
|
||||||
make_unknown(reporef.ref, self.explanation.handle,
|
make_unknown(reporef.ref, self.explanation.handle,
|
||||||
self.class_repo, self.commit_repo, self.trans)
|
self.class_repo, self.commit_repo, self.trans)
|
||||||
@ -1260,8 +1273,9 @@ class CheckIntegrity:
|
|||||||
if placeref.ref is None:
|
if placeref.ref is None:
|
||||||
none_handle = True
|
none_handle = True
|
||||||
placeref.ref = create_id()
|
placeref.ref = create_id()
|
||||||
|
try:
|
||||||
parent_place = self.db.get_place_from_handle(placeref.ref)
|
parent_place = self.db.get_place_from_handle(placeref.ref)
|
||||||
if not parent_place:
|
except HandleError:
|
||||||
# The referenced place does not exist in the database
|
# The referenced place does not exist in the database
|
||||||
make_unknown(placeref.ref,
|
make_unknown(placeref.ref,
|
||||||
self.explanation.handle, self.class_place,
|
self.explanation.handle, self.class_place,
|
||||||
@ -1284,8 +1298,9 @@ class CheckIntegrity:
|
|||||||
for ordinance in person.lds_ord_list:
|
for ordinance in person.lds_ord_list:
|
||||||
place_handle = ordinance.get_place_handle()
|
place_handle = ordinance.get_place_handle()
|
||||||
if place_handle:
|
if place_handle:
|
||||||
|
try:
|
||||||
place = self.db.get_place_from_handle(place_handle)
|
place = self.db.get_place_from_handle(place_handle)
|
||||||
if not place:
|
except HandleError:
|
||||||
# The referenced place does not exist in the database
|
# The referenced place does not exist in the database
|
||||||
# This is tested by TestcaseGenerator person "Broken17"
|
# This is tested by TestcaseGenerator person "Broken17"
|
||||||
# This is tested by TestcaseGenerator person "Broken18"
|
# This is tested by TestcaseGenerator person "Broken18"
|
||||||
@ -1306,8 +1321,9 @@ class CheckIntegrity:
|
|||||||
for ordinance in family.lds_ord_list:
|
for ordinance in family.lds_ord_list:
|
||||||
place_handle = ordinance.get_place_handle()
|
place_handle = ordinance.get_place_handle()
|
||||||
if place_handle:
|
if place_handle:
|
||||||
|
try:
|
||||||
place = self.db.get_place_from_handle(place_handle)
|
place = self.db.get_place_from_handle(place_handle)
|
||||||
if not place:
|
except HandleError:
|
||||||
# The referenced place does not exist in the database
|
# The referenced place does not exist in the database
|
||||||
make_unknown(place_handle,
|
make_unknown(place_handle,
|
||||||
self.explanation.handle, self.class_place,
|
self.explanation.handle, self.class_place,
|
||||||
@ -1325,8 +1341,9 @@ class CheckIntegrity:
|
|||||||
event = self.db.get_event_from_handle(key)
|
event = self.db.get_event_from_handle(key)
|
||||||
place_handle = event.get_place_handle()
|
place_handle = event.get_place_handle()
|
||||||
if place_handle:
|
if place_handle:
|
||||||
|
try:
|
||||||
place = self.db.get_place_from_handle(place_handle)
|
place = self.db.get_place_from_handle(place_handle)
|
||||||
if not place:
|
except HandleError:
|
||||||
# The referenced place does not exist in the database
|
# The referenced place does not exist in the database
|
||||||
make_unknown(place_handle,
|
make_unknown(place_handle,
|
||||||
self.explanation.handle, self.class_place,
|
self.explanation.handle, self.class_place,
|
||||||
@ -1506,8 +1523,9 @@ class CheckIntegrity:
|
|||||||
citation.set_reference_handle(source_handle)
|
citation.set_reference_handle(source_handle)
|
||||||
self.db.commit_citation(citation, self.trans)
|
self.db.commit_citation(citation, self.trans)
|
||||||
if source_handle:
|
if source_handle:
|
||||||
|
try:
|
||||||
source = self.db.get_source_from_handle(source_handle)
|
source = self.db.get_source_from_handle(source_handle)
|
||||||
if not source:
|
except HandleError:
|
||||||
# The referenced source does not exist in the database
|
# The referenced source does not exist in the database
|
||||||
make_unknown(source_handle, self.explanation.handle,
|
make_unknown(source_handle, self.explanation.handle,
|
||||||
self.class_source, self.commit_source, self.trans)
|
self.class_source, self.commit_source, self.trans)
|
||||||
@ -2123,16 +2141,18 @@ class CheckIntegrity:
|
|||||||
blink).format(quantity=blink)
|
blink).format(quantity=blink)
|
||||||
)
|
)
|
||||||
for (person_handle, family_handle) in self.broken_links:
|
for (person_handle, family_handle) in self.broken_links:
|
||||||
|
try:
|
||||||
person = self.db.get_person_from_handle(person_handle)
|
person = self.db.get_person_from_handle(person_handle)
|
||||||
if person:
|
except HandleError:
|
||||||
cn = person.get_primary_name().get_name()
|
|
||||||
else:
|
|
||||||
cn = _("Non existing child")
|
cn = _("Non existing child")
|
||||||
|
else:
|
||||||
|
cn = person.get_primary_name().get_name()
|
||||||
try:
|
try:
|
||||||
family = self.db.get_family_from_handle(family_handle)
|
family = self.db.get_family_from_handle(family_handle)
|
||||||
pn = family_name(family, self.db)
|
except HandleError:
|
||||||
except:
|
|
||||||
pn = _("Unknown")
|
pn = _("Unknown")
|
||||||
|
else:
|
||||||
|
pn = family_name(family, self.db)
|
||||||
self.text.write('\t')
|
self.text.write('\t')
|
||||||
self.text.write(
|
self.text.write(
|
||||||
_("%(person)s was removed from the family of %(family)s\n")
|
_("%(person)s was removed from the family of %(family)s\n")
|
||||||
@ -2147,16 +2167,18 @@ class CheckIntegrity:
|
|||||||
plink).format(quantity=plink)
|
plink).format(quantity=plink)
|
||||||
)
|
)
|
||||||
for (person_handle, family_handle) in self.broken_parent_links:
|
for (person_handle, family_handle) in self.broken_parent_links:
|
||||||
|
try:
|
||||||
person = self.db.get_person_from_handle(person_handle)
|
person = self.db.get_person_from_handle(person_handle)
|
||||||
if person:
|
except HandleError:
|
||||||
cn = person.get_primary_name().get_name()
|
|
||||||
else:
|
|
||||||
cn = _("Non existing person")
|
cn = _("Non existing person")
|
||||||
family = self.db.get_family_from_handle(family_handle)
|
|
||||||
if family:
|
|
||||||
pn = family_name(family, self.db)
|
|
||||||
else:
|
else:
|
||||||
pn = family_handle
|
cn = person.get_primary_name().get_name()
|
||||||
|
try:
|
||||||
|
family = self.db.get_family_from_handle(family_handle)
|
||||||
|
except HandleError:
|
||||||
|
pn = _("Unknown")
|
||||||
|
else:
|
||||||
|
pn = family_name(family, self.db)
|
||||||
self.text.write('\t')
|
self.text.write('\t')
|
||||||
self.text.write(
|
self.text.write(
|
||||||
_("%(person)s was restored to the family of %(family)s\n")
|
_("%(person)s was restored to the family of %(family)s\n")
|
||||||
@ -2173,16 +2195,18 @@ class CheckIntegrity:
|
|||||||
slink).format(quantity=slink)
|
slink).format(quantity=slink)
|
||||||
)
|
)
|
||||||
for (person_handle, family_handle) in self.broken_parent_links:
|
for (person_handle, family_handle) in self.broken_parent_links:
|
||||||
|
try:
|
||||||
person = self.db.get_person_from_handle(person_handle)
|
person = self.db.get_person_from_handle(person_handle)
|
||||||
if person:
|
except HandleError:
|
||||||
cn = person.get_primary_name().get_name()
|
|
||||||
else:
|
|
||||||
cn = _("Non existing person")
|
cn = _("Non existing person")
|
||||||
family = self.db.get_family_from_handle(family_handle)
|
|
||||||
if family:
|
|
||||||
pn = family_name(family, self.db)
|
|
||||||
else:
|
else:
|
||||||
|
cn = person.get_primary_name().get_name()
|
||||||
|
try:
|
||||||
|
family = self.db.get_family_from_handle(family_handle)
|
||||||
|
except HandleError:
|
||||||
pn = _("None")
|
pn = _("None")
|
||||||
|
else:
|
||||||
|
pn = family_name(family, self.db)
|
||||||
self.text.write('\t')
|
self.text.write('\t')
|
||||||
self.text.write(
|
self.text.write(
|
||||||
_("%(person)s was restored to the family of %(family)s\n")
|
_("%(person)s was restored to the family of %(family)s\n")
|
||||||
|
Loading…
Reference in New Issue
Block a user