mirror of
https://github.com/VectifyAI/PageIndex.git
synced 2026-07-15 21:11:05 +02:00
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:
parent
2cab6b5be9
commit
cc7e43c810
1 changed files with 1 additions and 1 deletions
|
|
@ -192,7 +192,7 @@ def structure_to_list(structure):
|
||||||
|
|
||||||
def get_leaf_nodes(structure):
|
def get_leaf_nodes(structure):
|
||||||
if isinstance(structure, dict):
|
if isinstance(structure, dict):
|
||||||
if not structure['nodes']:
|
if not structure.get('nodes'):
|
||||||
structure_node = copy.deepcopy(structure)
|
structure_node = copy.deepcopy(structure)
|
||||||
structure_node.pop('nodes', None)
|
structure_node.pop('nodes', None)
|
||||||
return [structure_node]
|
return [structure_node]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue