From cc7e43c810311677daf0d0f2a7f4e04cd315cf77 Mon Sep 17 00:00:00 2001 From: Chirag Bansal Date: Fri, 3 Jul 2026 03:48:29 -0400 Subject: [PATCH] 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 --- pageindex/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pageindex/utils.py b/pageindex/utils.py index cfa8782..c40e6ba 100644 --- a/pageindex/utils.py +++ b/pageindex/utils.py @@ -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]