[Zope-CMF] Re: Delete trouble
Philipp von Weitershausen
philipp at weitershausen.de
Mon Mar 26 16:24:59 EDT 2007
Dieter Maurer wrote:
> Martin Aspeli wrote at 2007-3-25 12:46 +0100:
>> I agree, except I think there could potentially be lots of places where
>> this could be happening. In the general case, it's probably safe for
>> that code to assume the utility is there, and treat it as an error if
>> it's not, but during site deletion, it is probably at the mercy of the
>> order of deletions. At least that's my guess.
> I would not find is a good approach, if exceptions were silently
Let's look at this closer:
- There's probably an event subscriber for IObjectBeforeDeleteEvent on
all Plone or CMF objects that makes sure that the deleted item is also
purged from the unique ID tool. So far so good.
- If that subscriber uses getUtility() calls and doesn't catch a
ComponentLookupError, it bluntly assumes that all such content objects
must live in an environment that has a unique ID utility. That's asking
for a lot (it's almost as bad as simply wanting to be able to acquire
portal_uuid or whatever it's called).
- To make reuse easier, the suggested pattern is to check if such a
utility can be found and then do the unregistering (or even registering
when the object is added). If the utility can't be found, then that's
too bad but shouldn't impact the actual use of the content type. After
all, it's just a dumb content type.
This isn't about silently suppressing exceptions, it's defensive
programming to increase flexibility.
> If we know that during deletions exceptional cases could happen,
> we should inform the component lookup process that we are doing
> deletions such that it can be less strict in its behaviour.
"Informing the component lookup process" is exactly the queryUtility()
call that I meant. It returns None if the component can't be found. In
combination for a check if the utility is None or not, this is the "less
strict behaviour" that you're asking for.
> However, usually the "I am going to be deleted" event is
> signalled before the actual deletion takes place. Therefore, the
> event processing still should find all utilities around.
Not if you haven't traversed into site. Then the local utilities won't
be found. I suggest reading the chapter on Sites in my book.
http://worldcookery.com -- Professional Zope documentation and training
More information about the Zope-CMF