From 1e78b9fe7c295c43376425e574a4b3644cc25820 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Sun, 21 May 2023 09:28:29 +0100 Subject: [PATCH] Bug #2019457: Tag browser - transient right click error. The search category can disappear from field_metadata. Perhaps other dynamic categories can as well. The implication is that dynamic categories are being removed, but how that would happen is a mystery. I suspect a plugin is operating on the "real" field_metadata instead of a copy, thereby changing the dict used by the rest of calibre. As it can happen, to avoid key errors check that a category exists before offering to unhide it. --- src/calibre/gui2/tag_browser/view.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/tag_browser/view.py b/src/calibre/gui2/tag_browser/view.py index 7e21e755f3..dad222f99a 100644 --- a/src/calibre/gui2/tag_browser/view.py +++ b/src/calibre/gui2/tag_browser/view.py @@ -722,7 +722,16 @@ class TagsView(QTreeView): # {{{ added_show_hidden_categories = True m = self.context_menu.addMenu(_('Show category')) m.setIcon(QIcon.ic('plus.png')) - for col in sorted(self.hidden_categories, + # The search category can disappear from field_metadata. Perhaps + # other dynamic categories can as well. The implication is that + # dynamic categories are being removed, but how that would + # happen is a mystery. I suspect a plugin is operating on the + # "real" field_metadata instead of a copy, thereby changing the + # dict used by the rest of calibre. + # + # As it can happen, to avoid key errors check that a category + # exists before offering to unhide it. + for col in sorted((c for c in self.hidden_categories if c in self.db.field_metadata), key=lambda x: sort_key(self.db.field_metadata[x]['name'])): ac = m.addAction(self.db.field_metadata[col]['name'], partial(self.context_menu_handler, action='show', category=col))