[Product-Developers] Re: Local utilities - ComponentLookupError
optilude+lists at gmail.com
Tue Jun 9 14:49:56 UTC 2009
Derek Broughton wrote:
> I'm trying to implement a local utility in the manner suggested by Martin
> Aspeli on p 275+ of /Professional Plone Development/.
> The control panel stuff works fine - the entries in the configlet persist
> over restarts of the system, and clearly the componentregistry.xml is right,
> because (a) I can see it in portal_setup, and (b) the configlet works.
> However, if I try to use the utility in Zope startup code (from
> configure.zcml) I get a ComponentLookupError.
That's because the utility is installed in the local site registry, but
your startup code executes outside this context and only has access to
components in the global registry.
Think about what would happen if you have two Plone sites with different
> Is there some point in the startup process that I have to wait for before I
> can use local utilities? Or do I have to physically do something to set the
> "Site" before I can use local utilities in startup code?
You can use zope.app.component.hooks.setSite(), but I'm not sure if
it'll work during app startup. You'd need to get hold of the Plone site
Most likely, whatever you're doing should not be done on startup.
Perhaps you want to do it lazily on demand and cache globally? A
variable cached with plone.memoize.forever may be an interesting option.
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book
More information about the Product-Developers