[Product-Developers] Re: Local utilities - ComponentLookupError

Derek Broughton derek at pointerstop.ca
Tue Jun 9 17:52:21 UTC 2009

Martin Aspeli wrote:

> Derek Broughton wrote:

>> 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
> configuration.

I have been and it just about drove me nuts :-)
>> 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
> root somehow.

Thanks.  For the specific requirements that wouldn't be an issue - there's 
just one site.
> Most likely, whatever you're doing should not be done on startup.

LOL.  I'd come to that conclusion.  The real problem was that bits of code 
that really didn't need to know about the database connection were getting 
invoked by <browser:page> directives, and trying to initialize the 
connection.  Getting that code disentangled solved the issue.

> Perhaps you want to do it lazily on demand and cache globally? 

Unfortunately it was only "like" your example - I was trying to use 
z3c.saconfig rather than collective.lead, because I'm using collective.tin 
which has moved to z3c.saconfig, and I was having a heck of a time figuring 
out where I could put a hook to invoke this code on demand.  I've finally 
found a way - it's not pretty, but it's good enough for the moment.

Thanks Martin

More information about the Product-Developers mailing list