Skip to content

fix: get_leaf_nodes KeyError on nodes-less leaf nodes - #453

Open
Manish2102 wants to merge 1 commit into
VectifyAI:mainfrom
Manish2102:fix/get-leaf-nodes-keyerror
Open

fix: get_leaf_nodes KeyError on nodes-less leaf nodes#453
Manish2102 wants to merge 1 commit into
VectifyAI:mainfrom
Manish2102:fix/get-leaf-nodes-keyerror

Conversation

@Manish2102

Copy link
Copy Markdown

clean_node() deletes the nodes key entirely from childless nodes during tree cleanup instead of setting it to an empty list, so get_leaf_nodes()'s direct structure['nodes'] access raised KeyError on any tree produced by the normal pipeline (#330).

clean_node() deletes the `nodes` key entirely from childless nodes
during tree cleanup instead of setting it to an empty list, so
get_leaf_nodes()'s direct `structure['nodes']` access raised KeyError
on any tree produced by the normal pipeline (VectifyAI#330).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings September 1, 2026 07:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a crash in pageindex.utils.get_leaf_nodes() when leaf nodes have no nodes key (as produced by the normal list_to_tree() cleanup pipeline described in #330).

Changes:

  • Update get_leaf_nodes() to use structure.get('nodes') instead of direct structure['nodes'] access to avoid KeyError on leaf nodes missing the key.
  • Add regression tests covering both missing nodes keys and explicit empty nodes: [] leaf nodes, plus list-of-trees input handling.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
pageindex/utils.py Makes leaf detection tolerant of missing nodes keys to prevent KeyError in normal pipeline output.
tests/test_utils.py Adds regression tests ensuring get_leaf_nodes() handles missing/empty nodes and list inputs correctly.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants