Skip to content

Fix move_before to the leftmost child position - #122

Open
arancool3000 wants to merge 1 commit into
uralbash:masterfrom
arancool3000:fix/68-move-before-leftmost
Open

arancool3000 wants to merge 1 commit into
uralbash:masterfrom
arancool3000:fix/68-move-before-leftmost

Conversation

@arancool3000

Copy link
Copy Markdown

What

node.move_before(x) where x is the first child of its parent did nothing (#68). The left-sibling search also ignored parent_id and had no ORDER BY, so a same-level cousin from another subtree could be taken as the left sibling and the node moved under the wrong parent.

Fix

In mptt_before_update (events.py): filter the left-sibling query by the target's parent and order by lft; when there is no left sibling and the target has a parent, set the node's parent to it and skip the "no move" early return so the existing insert-as-first-child path runs.

Tests

test_move_before_leftmost_child (moves node 6 before node 5, with cousin node 3 at the same level to the left). It fails on master and passes with the fix. Full suite: 297 passed, 1 xfailed (master: 291 passed). flake8 clean.

Fixes #68

AI-assisted (Claude); reviewed before submission.

move_before on a parent's first child returned early without moving,
and the left-sibling lookup could pick a same-level cousin from another
subtree. Restrict the lookup to the same parent, order by lft, and
insert as the leftmost child when there is no left sibling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Moving node to leftmost position doesn't work

1 participant