Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions GTG/core/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,22 @@ def from_xml(self, xml: _Element) -> None:
for element in elements:
child_id: UUID = UUID(element.get('id'))
hex_parent_id: Optional[str] = element.get('parent')
parent_id: Optional[UUID] = None

if hex_parent_id is None:
continue

try:
parent_id: UUID = UUID(hex_parent_id)
parent_id = UUID(hex_parent_id)
except ValueError:
log.debug('Malformed parent UUID: %s', tag, hex_parent_id)
log.debug('Parent id is not a valid UUID: %s', hex_parent_id)

if parent_id is None and hex_parent_id in self.lookup_names:
log.debug('Parent id recognised as tag name from an old format: %s', hex_parent_id)
parent_id = self.lookup_names[hex_parent_id].id

if parent_id is None:
log.error('Failed to identify parent tag: %s', hex_parent_id)
continue

try:
Expand Down
13 changes: 13 additions & 0 deletions tests/core/test_tag_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ def test_xml_load_tree(self):
self.assertEqual(store.count(root_only=True), 2)


def test_xml_load_tree_with_old_parent_naming(self):
store = TagStore()
xml_doc = XML('''
<taglist>
<tag id="df4db599-63f8-4fc8-9f3d-5454dcadfd78" name="money"/>
<tag id="ef4db599-73f8-4fc8-9f3d-5454dcadfd78" name="errands" parent="money"/>
</taglist>
''')

store.from_xml(xml_doc)
self.assertIs(store.find("errands").parent,store.find("money"))


def test_xml_load_bad(self):
store = TagStore()
xml_doc = XML('''
Expand Down