Skip to content

Commit

Permalink
tree_id expires after flushing fixes #33
Browse files Browse the repository at this point in the history
  • Loading branch information
uralbash committed Oct 10, 2014
1 parent 3a0b225 commit b1c3010
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions sqlalchemy_mptt/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ def after_flush_postexec(self, session, context):
self.instances.discard(parent)
session.expire(parent, ['left', 'right'])
parent = self.get_parent_value(parent)
else:
session.expire(instance, ['tree_id', ])

@staticmethod
def get_parent_value(instance):
Expand Down
10 changes: 9 additions & 1 deletion sqlalchemy_mptt/tests/tree_testing_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ def test_move_tree_to_another_tree(self):
"""
node = self.session.query(self.model).\
filter(self.model.ppk == 12).one()
filter(self.model.ppk == 12).one()
node.parent_id = 7
self.session.add(node)
# id lft rgt lvl parent tree
Expand Down Expand Up @@ -1715,3 +1715,11 @@ def test_leftsibling_in_level(self):
self.assertEqual(node8.leftsibling_in_level().idd, node6.ppk)
self.assertEqual(node6.leftsibling_in_level().idd, node5.ppk)
self.assertEqual(node3.leftsibling_in_level(), None)

def test_session_expire(self):
"""https://github.com/ITCase/sqlalchemy_mptt/issues/33"""
node = self.session.query(self.model).filter(self.model.ppk == 4).one()
node.move_after('1')
self.session.flush()
self.assertEqual(node.tree_id, 2)
self.assertEqual(node.parent_id, None)

0 comments on commit b1c3010

Please sign in to comment.