fix: reassigning Node.edge no longer detaches the node from its parent#235
Open
steps-re wants to merge 1 commit into
Open
fix: reassigning Node.edge no longer detaches the node from its parent#235steps-re wants to merge 1 commit into
Node.edge no longer detaches the node from its parent#235steps-re wants to merge 1 commit into
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #235 +/- ##
==========================================
+ Coverage 88.81% 88.82% +0.01%
==========================================
Files 114 114
Lines 12963 12975 +12
==========================================
+ Hits 11513 11525 +12
Misses 1450 1450
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Node._set_edge() removed the node from its parent's _child_nodes list as a side effect of swapping in a new Edge object, without re-adding it anywhere or clearing _parent_node. Since a node's tail_node is derived from head_node._parent_node (not stored independently), this detachment had no bookkeeping purpose and only corrupted the tree: after 'node.edge = new_edge', the node vanished from its parent's children while node.parent_node still pointed at the old parent. Signed-off-by: Mike German <mike@stepsventures.com>
steps-re
force-pushed
the
fix/node-parent-reindex
branch
from
July 14, 2026 15:12
7a5675e to
9c829d1
Compare
Contributor
Author
|
Rebased on main to kill the conflict. Was just a collision with a sibling PR that dropped |
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.
Split out of #234 at @mmore500's request, so the parent/children bookkeeping change can be discussed on its own.
What it changes
Node._set_edge()(the setter behindnode.edge = new_edge) removed the node from its parent's_child_nodeslist as a side effect of swapping in a newEdge:This patch removes those lines. A node's
tail_nodeis derived fromhead_node._parent_node, not stored on the edge, so swapping the edge object has no bearing on where the node sits in the tree. As written,node.edge = new_edgesilently dropped the node from its parent's children whilenode.parent_nodestill pointed at the old parent, leaving the tree in an inconsistent state.The change is covered by a regression test (
test_edge_setting_does_not_corrupt_parent_child_bookkeeping) asserting that after reassigning a child'sedge, the parent still lists the child and the child still points back at the parent.Why it's split from #234
#234 is a batch of small, independent static-analysis fixes. This one touches live tree-mutation semantics rather than a self-contained bug, so it warrants its own review thread. The rest of #234 (including the unrelated
distance_from_root()None-parent fix in the same file) stays there.Open question from @mmore500
Should
_parent_nodealso be reset when the edge is reassigned? This PR only stops the node from being removed from the parent's_child_nodeslist, it does not touch_parent_node. If the intended semantics of reassigning an edge are "detach this node from its current parent entirely," then both sides of the link (_parent_nodeand the parent's_child_nodes) should be cleared together, rather than the current half-and-half. Happy to adjust in whichever direction you prefer.