fix: handle missing nodes key in get_leaf_nodes#351
Open
fooSynaptic wants to merge 1 commit into
Open
Conversation
Author
|
Hi @KylinMountain — gentle ping when you have a moment. This PR fixes #330 ( Happy to adjust anything per your feedback — thanks for maintaining PageIndex! |
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.
Fixes #330
Problem
get_leaf_nodes()crashes withKeyError: 'nodes'when traversing trees built bylist_to_tree().list_to_tree()runsclean_node()on every node. For nodes with no children,clean_node()deletes thenodeskey entirely (del node['nodes']), rather than leaving it as an empty list. Later,get_leaf_nodes()checks leaf status viastructure['nodes'], which raisesKeyErroron those nodes.Fix
Use
.get('nodes')instead of direct key access:When the key is absent,
.get('nodes')returnsNone(falsy), so the node is correctly treated as a leaf. This matches how other helpers in the same file already accessnodes(e.g.format_structure,is_leaf_node).Tests
Added
tests/test_issue_330.py:nodeskey is returned as a leaflist_to_tree()→get_leaf_nodes()end-to-end traversal does not raisepytest tests/test_issue_330.py -v— 2 passed locally.