From 607d4889d60284af82d8b096697ead0adcd0bbba Mon Sep 17 00:00:00 2001 From: Tom Samstag Date: Tue, 29 Mar 2016 00:11:56 -0700 Subject: [PATCH 1/2] fix the name map of tags in DictionaryDb DictionaryDb had a bug where the same tag could end up in the name mapping multiple times. This was most easily seen when loading a gramps xml into a DictionaryDb, where an extra entry with the tag name of '' would be created and would ultimately be referencing the last-created Tag (also referenced by its proper tag name). This change makes sure that when editing a tag, any existing references in the name mapping are deleted before adding. --- gramps/plugins/database/dictionarydb.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gramps/plugins/database/dictionarydb.py b/gramps/plugins/database/dictionarydb.py index 3641b77a5..a1c0afdb8 100644 --- a/gramps/plugins/database/dictionarydb.py +++ b/gramps/plugins/database/dictionarydb.py @@ -520,6 +520,11 @@ class DictionaryDb(DbGeneric): emit = None if tag.handle in self.tag_map: emit = "tag-update" + existing_names = [existing_name for existing_name, existing_tag in + self._tag_name_dict.items() + if existing_tag.handle == tag.handle] + for existing_name in existing_names: + del self._tag_name_dict[existing_name] self._tag_dict[tag.handle] = tag self._tag_name_dict[tag.name] = tag else: From ea78dff2f20cdb046ad7f4ee8465b112ac669ba5 Mon Sep 17 00:00:00 2001 From: Tom Samstag Date: Tue, 29 Mar 2016 09:03:24 -0700 Subject: [PATCH 2/2] make tag name map fix more readable I think this version of the fix is more readable --- gramps/plugins/database/dictionarydb.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/gramps/plugins/database/dictionarydb.py b/gramps/plugins/database/dictionarydb.py index a1c0afdb8..29e762fc7 100644 --- a/gramps/plugins/database/dictionarydb.py +++ b/gramps/plugins/database/dictionarydb.py @@ -520,11 +520,9 @@ class DictionaryDb(DbGeneric): emit = None if tag.handle in self.tag_map: emit = "tag-update" - existing_names = [existing_name for existing_name, existing_tag in - self._tag_name_dict.items() - if existing_tag.handle == tag.handle] - for existing_name in existing_names: - del self._tag_name_dict[existing_name] + for old_name, old_tag in list(self._tag_name_dict.items()): + if old_tag.handle == tag.handle: + del self._tag_name_dict[old_name] self._tag_dict[tag.handle] = tag self._tag_name_dict[tag.name] = tag else: