[Grok-dev] global_adapter method no longer gets adapts from factory annotation.

Jan-Carel Brand lists at opkode.com
Thu Mar 15 12:40:00 UTC 2012


Hi folks

I'm hoping you can elucidate some changes that were introduced into
grokcore.component from version 2.0.

I'm developing with Plone/dexterity/z3c.form, currently using
grokcore.component 1.9 and trying to see if I can use a newer version
instead.

With grokcore.component > 1.9 I however get a
ConfigurationClonflictError, due to two global nameless adapters.

Here is the error's traceback: http://pastie.org/3600511

The two clashing adapters are two validators that I am registering via
grok.global_adapter. See here: http://pastie.org/3600499

So, looking inside grokcore/component/directive.py:global_adpter I see
that there are some changes made between 1.9 and 2.0 that cause this
breakage for me and I don't understand why and how things are supposed
to work from 2.0 onwards.

If you look at the registration of my adapters, I don't provide "adapts"
or "provides" kw args to global_adapter. The docstring of method
global_adapter itself says:

> If omitted, this information is deduced from the annotation on the 
> factory. 

In grokcore.component < 1.9, this happened explicitly:

>         if adapts is None:
>             adapts = getattr(factory, '__component_adapts__', None)
> 
But since 2.0 that code is now gone. I think it's the removal of that
line that breaks my adapters now. Since what happens is that my two
global adapters are registered against adapts=None and provides=None.

And of course, since they don't have names, they registration clashes.

Looking at the SVN log, I see that Martijn introduced the mentioned
change in global_adapter with the following explanation:

> r104104 | faassen | 2009-09-15 18:30:24 +0200 (Tue, 15 Sep 2009) | 6 
> <snip>
> 
> Upgrade to use the new Martian 0.12. This allowed us to 
> significantly simplify the way the context directive worked. It
> also made us realize it's bad form to use directives in the
> implementation of a directive - directive.bind.get() should only
> be used during Grok time, never during import time.
> 
To be honest, I don't see know how the above results in the changes in
global_adapter.
> 
I AM however using Martian 0.14. 

Also, providing names for my global adapters prevents the configuration
conflict, but my validators then don't get invoked. So that's not a
workaround/solution.
> 
So, can someone please give me some info on what is going on here? What
needs to be done to register unnamed global adapters? Why does the
global_adapter method no longer get the "adapts" annotation from the
factory?

Thanks a lot and sorry for the long post!
JC Brand

p.s: My grokcore versions:

>   '/home/jc/.buildout/eggs/martian-0.14-py2.6.egg',
>   '/home/jc/.buildout/eggs/grokcore.rest-1.2-py2.6.egg',
>   '/home/jc/.buildout/eggs/grokcore.view-2.6.1-py2.6.egg',
>   '/home/jc/.buildout/eggs/grokcore.security-1.5-py2.6.egg',
>   '/home/jc/.buildout/eggs/grokcore.component-2.4-py2.6.egg',
> 





More information about the Grok-dev mailing list