[Zope3-dev] substransactions and beforeDelete

Florent Guillaume fg at nuxeo.com
Wed Jan 7 06:26:42 EST 2004


I've been faced with the following Zope 2 problem in a consulting gig, 
and I'd like to be sure the use case is taken into account for Zope 3 as 
I think it's quite important. I haven't been able to follow Zope 3 
lately, sorry for any duplication.

We wanted to be able to have some objects veto their deletion in some 
cases (user has insufficient roles). This had to work even if it was a 
subobject of the object being deleted that had a veto, in which case the 
deletion of the toplevel object would also be vetoed.

To do that in Zope 2, I first patched manage_beforeDelete to make it 
raise a subclass of BeforeDeleteException if the object vetoed deletion, 
and had the high-level code catch this exception to be able to display a 
message to the user explaining what happened and why deletion could not 
be successful.

But, while before implementing it I'd always thought it would work, 
there is a problem. In the manage_beforeDelete recursion, other 
bookkeeping tasks are done, most notably removal from the CMF catalog. 
If we just raise an exception and catch it, the bookkeeping tasks for 
other objects walked before in the recursion will not be rolled back, 
even though no object is actually deleted... So actually doing the veto 
in the middle of the manage_beforeDelete recursion cannot work.

What I would have liked to do is to be able to start a substransaction 
before the manage_beforeDelete thing is called, and either commit it or 
have it rolled back if my BeforeDeleteException is raised. This way, the 
unindexing would be rolled back. But from my understanding, Zope 2's 
ZODB cannot do that.

So my question is, would this be possible in Zope 3 ? Setting a 
subtransaction point and doing a rollback of only that subtransaction ?

(Note, to solve the problem in Zope 2, I now do a pre-deletion check 
that does a recursion and tests if deletion will be successful. If so, 
and only then, I do the real deletion.)

Florent


-- 
Florent Guillaume, Nuxeo (Paris, France)
+33 1 40 33 79 87  http://nuxeo.com  mailto:fg at nuxeo.com




More information about the Zope3-dev mailing list