fix: use .get() in get_leaf_nodes to avoid KeyError on leaf nodes - #331
Merged
KylinMountain merged 1 commit intoJul 3, 2026
Merged
Conversation
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 VectifyAI#330
KylinMountain
approved these changes
Jul 3, 2026
KylinMountain
left a comment
Collaborator
There was a problem hiding this comment.
Thanks @ChiragB254, nice catch — consistent with the rest of the codebase. Merging! 🙏
GhislainAdon
pushed a commit
to GhislainAdon/iroko-rag
that referenced
this pull request
Jul 6, 2026
…ctifyAI#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 VectifyAI#330
KylinMountain
added a commit
that referenced
this pull request
Jul 7, 2026
…on shims The new SDK copied the legacy indexing pipeline into pageindex/index/ instead of moving it, leaving two divergent copies of page_index.py / page_index_md.py / utils.py. They had already drifted (the legacy copy still compared IndexConfig booleans against 'yes' — a separate fix), and every pipeline change had to be applied twice. Make pageindex/index/ the single source of truth (same pattern as the LegacyCloudAPI shim for the 0.2.x cloud SDK): - pageindex/index/utils.py absorbs the 27 legacy-only helpers/classes (get_page_tokens, convert_page_to_int, ConfigLoader, PDF text helpers, ...) so it's the sole utils module. Reconciled the diverged funcs: kept the modern versions, backported the #331 get_leaf_nodes .get() fix, and restored remove_fields' max_len parameter (superset). - index/page_index*.py now import `from .utils import *`; index/legacy_utils.py (a re-export of the old top-level utils) deleted. - Top-level page_index.py / page_index_md.py / utils.py become thin re-export shims that emit PendingDeprecationWarning. The md_to_tree shim coerces legacy 'yes'/'no' string flags to bool (the canonical version is boolean-typed). - ConfigLoader no longer reads the deleted config.yaml; it builds defaults from IndexConfig (was an unconditional FileNotFoundError). - __init__.py and retrieve.py import from pageindex.index.* directly so `import pageindex` does not trip the shims. Adds tests/test_legacy_shims.py pinning the contract: clean top-level import doesn't warn, legacy submodule imports warn, symbols still resolve, shim and canonical share one implementation, the #331 fix and ConfigLoader-without-yaml both hold, and the md_to_tree coercion works. Claude-Session: https://claude.ai/code/session_01Kx5DgKbhK1N8autqXH8SmS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
get_leaf_nodes()crashed withKeyError: 'nodes'when called on a tree built by the standard pipelinelist_to_tree()callsclean_node()which deletes thenodeskey entirely from leaf nodes (rather than setting it to[])structure['nodes']directly on those nodes raisesKeyErrorstructure['nodes']withstructure.get('nodes')— returnsNone(falsy) safely when the key is absentChanges
pageindex/utils.py— one-line change inget_leaf_nodes:Why this is consistent
Every other
nodesaccess in the codebase already uses.get():format_structure→structure.get('nodes')is_leaf_node→node.get('nodes')print_tree→node.get('nodes')Test
Fixes #330