[Zope3-dev] substransactions and beforeDelete

Jim Fulton jim at zope.com
Wed Jan 7 07:11:51 EST 2004


Florent Guillaume wrote:
> 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.

Why are you catching the exception?

> 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.

But it will be rolled back if an exception is raised.  I'm puzzled that
you are catching the exception.

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

well, of course, but this sounds too complex.

> (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.)

You can roll-back subtransactions in Zope 2.  But the solution
feels to complex to me.  I don't understand why you are catching
and not reraising an error.

Jim

-- 
Jim Fulton           mailto:jim at zope.com       Python Powered!
CTO                  (540) 361-1714            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org




More information about the Zope3-dev mailing list