[Zope-dev] Re: [Warning] Zope 3 component architecture (CA) not reliably usable for registrations from Python

Philipp von Weitershausen philipp at weitershausen.de
Wed Jan 10 09:40:51 EST 2007

Dieter Maurer wrote:
> I tried to use Zope3 events to get informed when requests start and end.
> One of our modules (the interface module to "jpype") requires such
> a notification for reliable work. Therefore, it tried to register
> the corresponding subscriptions on import of this module.

That is an uncommon approach, at least it used to be. Typically, we 
first have a bootstrap level and then we register things. During the 
bootstrap level, the Component Architecture is initialized.

Things changed a bit after Zope 2.8/X3 3.0. Nowadays, the Component 
Architecture doesn't need any setup anymore and you can do registrations 
on import. I'd still recommend against that.

> Unfortunately, this works very unreliably -- for the following reasons:
>   The CA performs by itself only extremely minimal initialization.
>   Especially, it does not register the "Adapters" service, necessary
>   for the registration of event subscriptions.
>   The full CA initialization is only performed quite late, in the call
>   to "Products.Five.initialize".
>   Event notification registration attempts before this time will fail
>   (with a "ComponentLookupError: 'Adapters'"), 
>   those performed after this time will succeed.
> The "Five" initialization is stupid enough that it will fail
> when the service registration for 'Adapters' has already been performed.

That's because Five assumes it's responsible for the setup layer. I 
suggest to register components through ZCML. Five will pick up 
configure.zcml in products automatically *after* everything has been set 
up properly. That's the canonical way, at least in Zope 2.8/X3 3.0

> At the current state, event notifications can reliably only be defined 
> via ZCML. This is unfortunate for our use case where the registration
> should be bound to the import of a given module.

I typically find it quite magic when application policy things happen at 

   Never mix mechanism with policy
     -- Brooks' Second Law of Software Reuse


P.S.: I agree with Martijn, the big "warning" is uncalled for. You're 
just trying to fight the semantics of the framework.

http://worldcookery.com -- Professional Zope documentation and training
2nd edition of Web Component Development with Zope 3 is now shipping!

More information about the Zope-Dev mailing list