Martin Aspeli wrote:
The UniqueIDAnnotationTool should probably do a *query*Utility (which will return None in case the utility can't be found) and simply not do anything in such a case. The canonical way of expressing such fail-safe routines is therefore:

   component = query{Utility|Adapter|MultiAdapter}(...)
   if component is not None:

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,

I disagree. Componentized code gains maximum reusability if it assumes as little as possible about the setup and other components, other than what interfaces promise (defensive programming). I bet that a lot of places where the UniqueIDAnnotationTool is looked up, it's all about updating the some information and if the tool ain't there, then I think it's safe to simply skip that step. Code that directly needs the UniqueIDAnnotationTool to do its job will have to assume that it can get the utility, but all other code shouldn't have to.

but during site deletion, it is probably at the mercy of the order of deletions. At least that's my guess.

It might be at the mercy of event subscriber execution order, but it's really the site traversal issue I think:

It *could* also be a site manager/traversal issue, I guess - I'm one level above the Plone site when I delete this, so possibly it's not finding the right site manager? Not sure how that works...\

*sigh* Chapter XYZ in my book explains the process :). Whenever you traverse over a site, its site manager becomes the active component registry. So if you haven't traversed over that site yet, the utilities in that site won't be found. It's that simple.

-- -- Professional Zope documentation and training

Zope-CMF maillist  -

See for bug reports and feature requests

Reply via email to