[Zope3-dev] substransactions and beforeDelete
Florent Guillaume
fg at nuxeo.com
Wed Jan 7 07:19:37 EST 2004
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.
>> 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
>
--
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