Thanks Michael,

It turns out that when remove node with children, sqlalchemy by defaults 
first update children (set parent_id=None) and then delete node. When I set 
cascade="all,delete" it's delete node one by one (w/o update).

вторник, 22 апреля 2014 г., 20:39:21 UTC+6 пользователь Michael Bayer 
написал:
>
> not clear.    Sometimes, the unit of work does different things based on 
> the random ordering of dictionaries, and arbitrary changes in code can 
> trigger these ordering changes.  you might want to try running the script 
> repeatedly to make sure these two behaviors are consistent; then try to 
> slowly remove one by one things from that extra event listen; eg. have it 
> listen on a different function, then remove elements from that function one 
> by one until you find what triggers the difference.
>
>
>
>
> On Apr 22, 2014, at 4:38 AM, uralbash <svint...@gmail.com <javascript:>> 
> wrote:
>
> Can anybody tell what I'm doing wrong
>
> I have method with which register event (before_update, after_delete, 
> before_insert) 
> https://github.com/ITCase/sqlalchemy_mptt/blob/b0efead7a8ee5acc063b68ee3bfc756af4689d6e/sqlalchemy_mptt/mixins.py#L69
>
> @classmethoddef register_tree(cls):
>     event.listen(cls, "before_insert", cls.mptt_before_insert)
>     event.listen(cls, "after_delete", cls.mptt_after_delete)
>     event.listen(cls, "before_update", cls.mptt_before_update)
>
>
> When I registered event and try to delete row (
> https://github.com/ITCase/sqlalchemy_mptt/blob/b0efead7a8ee5acc063b68ee3bfc756af4689d6e/sqlalchemy_mptt/tests.py#L104
> ).
>
> class Tree(Base, BaseNestedSets):
>     __tablename__ = "tree"
>
>     id = Column(Integer, primary_key=True)
> Tree.register_tree()
> def test_delete_node(self):
>     node = self.session.query(Tree).filter(Tree.id == 4).one()
>     self.session.delete(node)
>     # id lft rgt lvl parent tree
>     self.assertEqual([(1, 1, 16, 1, None, 1),
>                       (2, 2, 5, 2, 1, 1),
>                       (3, 3, 4, 3, 2, 1),
>                       (7, 6, 15, 2, 1, 1),
>                       (8, 7, 10, 3, 7, 1),
>                       (9, 8, 9, 4, 8, 1),
>                       (10, 11, 14, 3, 7, 1),
>                       (11, 12, 13, 4, 10, 1)], self.result.all())
>
> Called before_update method instead after_delete. But if I comment 
> before_update event (
> https://github.com/ITCase/sqlalchemy_mptt/blob/b0efead7a8ee5acc063b68ee3bfc756af4689d6e/sqlalchemy_mptt/mixins.py#L72)
>  
> it's work fine.
>
> @classmethoddef register_tree(cls):
>     event.listen(cls, "before_insert", cls.mptt_before_insert)
>     event.listen(cls, "after_delete", cls.mptt_after_delete)
>     # event.listen(cls, "before_update", cls.mptt_before_update) <-- IF 
> comment this, called after_delete method. It's OK.
>
>
> Build status https://travis-ci.org/ITCase/sqlalchemy_mptt/builds/23428309
>
> What's wrong?
>
> I asked this on 
> stackoverflow.com<http://stackoverflow.com/questions/23198252/sqlalchemy-before-update-called-instead-after-delete>
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+...@googlegroups.com <javascript:>.
> To post to this group, send email to sqlal...@googlegroups.com<javascript:>
> .
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to