fix: to_dict() returns None for non-expanded nodes - #243
Closed
gaoflow wants to merge 1 commit into
Closed
Conversation
When a node has expanded=False, to_dict() skips the return statement entirely, returning None instead of the expected tag string or dict with data. This also breaks to_json() which returns 'null' for collapsed trees. Add else clause to handle the non-expanded case consistently with the expanded-but-empty-children case.
Collaborator
|
@gaoflow can you add a unit test for this case and make sure that all the tests pass? |
Author
|
This is already fixed on master — 700d9d7 rewrote On current master the repro gives |
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
Tree.to_dict()returnsNonewhen called on a node withexpanded=False, instead of the expected string (tag) or dict (with children). This also breaksto_json(), which returns"null"for collapsed trees.The root cause: when
self[nid].expandedisFalse, the method skips theifblock entirely and falls through without hitting areturnstatement, yieldingNoneby default.Reproduction:
Fix: Add an
elseclause to return the tag/dict-with-data when the node is not expanded, consistent with how leaf nodes (expanded=True, no children) are already handled.All 207 existing tests pass. AI-assisted.