Repository navigation
Fix move_after placing node one slot too far right (#67) - #121
Open
arancool3000 wants to merge 1 commit into
Open
arancool3000 wants to merge 1 commit into
arancool3000 wants to merge 1 commit into
Conversation
move_after/move_before captured the left sibling's lft/rgt before mptt_before_delete shifted it, so a node moved to the right within the same tree landed one slot too far and corrupted the tree. Fixes uralbash#67.
This branch has not been deployed
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.
What was wrong
In
mptt_before_update, the left sibling'slft/rgtare read beforemptt_before_deleteremoves the moving subtree. When the left sibling sits to the right of the moving node in the same tree, that removal shifts it left by the subtree size, but_insert_subtreestill used the stale values. The node landed too far right and the tree was corrupted (e.g. moving node 2 after its sibling 4 nested it inside node 7's range).Fix
Keep the left sibling's primary key alongside its position (for both
move_afterand themove_beforepath that resolves a left sibling) and re-read itslft/rgtright after the subtree is removed, just like the parent position is already re-read.How tested
test_move_after_right_sibling(moves node 2 after its right sibling 4). It failed before the fix and passes after.Fixes #67
AI-assisted (Claude); reviewed before submission.