Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move_after moves node too far right #67

Open
RafGb opened this issue Jan 21, 2020 · 2 comments
Open

move_after moves node too far right #67

RafGb opened this issue Jan 21, 2020 · 2 comments
Labels

Comments

@RafGb
Copy link

RafGb commented Jan 21, 2020

move_after moves element one position further than expected.
I think it's because after we called mptt_before_delete here, lft and rgt of left sibling has changed, but variable left_sibling still has old values which lead to incorrect values of delta_lft and delta_rgt in _insert_subtree

Here's test code:

class MoveRight(object):
    def test_move_right(self):
        self.session.query(self.model).delete()

        _level = self.model.get_default_level()
        pk_column = self.model.get_pk_column()

        self.session.add_all([
            self.model(**{pk_column.name: 1}),
            self.model(**{pk_column.name: 2, 'parent_id': 1}),
            self.model(**{pk_column.name: 3, 'parent_id': 1}),
            self.model(**{pk_column.name: 4, 'parent_id': 1}),
        ])

        # initial tree:
        #        1
        #   /    |   \
        #  2     3    4

        self.assertEqual(
            [
                (1, 1, 8, _level + 0, None, 1),
                (2, 2, 3, _level + 1, 1, 1),
                (3, 4, 5, _level + 1, 1, 1),
                (4, 6, 7, _level + 1, 1, 1)
            ],
            self.result.all()
        )

        # move 2 to right
        node2 = self.session.query(self.model).filter(pk_column == 2).one()
        node2.move_after("3")

        # expected result:
        #        1
        #   /    |   \
        #  3     2    4

        self.assertEqual(
            [
                (1, 1, 8, _level + 0, None, 1),
                (2, 4, 5, _level + 1, 1, 1),
                (3, 2, 3, _level + 1, 1, 1),
                (4, 6, 7, _level + 1, 1, 1)
            ],
            self.result.all()
        )
@uralbash uralbash added the bug label Aug 5, 2020
@Goomba41
Copy link

Goomba41 commented Apr 7, 2021

Hi! Has any progress?

1 similar comment
@moyueheng
Copy link

Hi! Has any progress?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants