[Zope3-dev] substransactions and beforeDelete

Jim Fulton jim at zope.com
Wed Jan 7 07:31:39 EST 2004


Florent Guillaume wrote:
> Jim Fulton wrote:
> 
>> 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?
> 
> 
> Because I want to display a nice message to the user. If I don't catch 
> the exception, it will go up to the Publisher that will display a 
> not-nice error message. Hm are you suggesting I could provide a custom 
> error message for that particular exception? That could work, but I 
> would have like the flexibility of catching the exception from normal 
> skin code and display my error message there.

Right.  This is much cleaner in Zope 3, as the publisher displays
exceptions using exception views.

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