From fd399323a614d74578f5e5b3a1fa709eade037f8 Mon Sep 17 00:00:00 2001 From: Paul Culley Date: Mon, 3 Sep 2018 19:16:21 -0500 Subject: [PATCH] Fix corrupted Bookmarks that can happen after Gramps crash (#655) Fixes #10759 --- gramps/gui/views/bookmarks.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gramps/gui/views/bookmarks.py b/gramps/gui/views/bookmarks.py index a29da9b5a..e81c6780a 100644 --- a/gramps/gui/views/bookmarks.py +++ b/gramps/gui/views/bookmarks.py @@ -54,6 +54,7 @@ from ..managedwindow import ManagedWindow from gramps.gen.utils.db import navigation_label from gramps.gen.const import URL_MANUAL_PAGE from gramps.gen.const import GRAMPS_LOCALE as glocale +from gramps.gen.errors import HandleError _ = glocale.translation.sgettext #------------------------------------------------------------------------- @@ -156,6 +157,7 @@ class Bookmarks(metaclass=ABCMeta): actions = [] count = 0 + bad_bookmarks = [] # list of bad bookmarks if self.dbstate.is_open() and len(self.bookmarks.get()) > 0: text.write('') @@ -169,6 +171,9 @@ class Bookmarks(metaclass=ABCMeta): count += 1 except AttributeError: pass + except HandleError: + # if bookmark contains handle to something missing now + bad_bookmarks.append(item) text.write('') text.write(BTM) @@ -177,6 +182,10 @@ class Bookmarks(metaclass=ABCMeta): self.active = self.uistate.uimanager.add_ui_from_string(text.getvalue()) self.uistate.uimanager.ensure_update() text.close() + # Clean up any bad bookmarks (can happen if Gramps crashes; + # modified bookmarks set is saved only on normal Gramps close) + for handle in bad_bookmarks: + self.bookmarks.remove(handle) @abstractmethod def make_label(self, handle):