fix: use .get() in get_leaf_nodes to avoid KeyError on leaf nodes (#331)

list_to_tree() deletes the 'nodes' key from leaf nodes entirely via
clean_node(). Direct access via structure['nodes'] raises KeyError on
these nodes. Using structure.get('nodes') returns None (falsy) safely,
consistent with how 'nodes' is accessed elsewhere in the codebase.

Fixes #330
This commit is contained in:
Chirag Bansal 2026-07-03 03:48:29 -04:00 committed by GitHub
parent 2cab6b5be9
commit cc7e43c810
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -192,7 +192,7 @@ def structure_to_list(structure):
def get_leaf_nodes(structure):
if isinstance(structure, dict):
if not structure['nodes']:
if not structure.get('nodes'):
structure_node = copy.deepcopy(structure)
structure_node.pop('nodes', None)
return [structure_node]