uralbash / sqlalchemy_mptt

SQLAlchemy nested sets mixin (MPTT)
http://sqlalchemy-mptt.readthedocs.io
MIT License
196 stars 32 forks source link

Flushing the session should expire the instance and it's children #33

Closed fayazkhan closed 9 years ago

fayazkhan commented 10 years ago

This test currently fails.

    def test_session_expire(self):
        node = self.session.query(self.model).filter(self.model.ppk == 4).one()
        node.move_after('1')
        self.session.flush()
        # self.session.expire(node)
        self.assertEqual(node.tree_id, 2)
        self.assertEqual(node.parent_id, None)

Expiring the node solves the problem. So shouldn't the after_flush_post_exec listener be expiring those attributes too? A simpler solution would be to update those values from mptt_before_update.

uralbash commented 10 years ago

Thank you for your issue, it,s very similar to #30 I'll add a check tree_id in after_flush_post_exec

fayazkhan commented 10 years ago

Shouldn't all the children also be expired there? Something similar to what you're doing for the parents?

uralbash commented 10 years ago

All the children expired with parent after flush. See example https://github.com/ITCase/sqlalchemy_mptt/commit/62779c9e9cc076143ed284ef6a2df547aff19279

uralbash commented 10 years ago

I created a new branch path-33 for this issue, until I can not pass this test https://github.com/ITCase/sqlalchemy_mptt/blob/path-33/sqlalchemy_mptt/tests/tree_testing_base.py#L1732