[Zope-dev] Zope.principalannotation bug report

Leonardo Rochael Almeida leorochael at gmail.com
Tue Jun 10 00:02:56 CEST 2014


Hi Christopher,

On 9 June 2014 16:29, Christopher Lozinski <lozinski at freerecruiting.com>
wrote:

> Here is an extract from the principalannotation configure.zcml file.
>
>    <adapter factory=".utility.annotations" />
>
>   <adapter
>       for="zope.security.interfaces.IPrincipal *"
>       factory=".utility.annotations"
>       />
>
> Clearly something is wrong.  Two copies, and no "provides" line.


The <adapter /> element only needs the `for` and `provides` attributes if
you want to give different values than the ones already declared on the
factory, or if the factory doesn't have them. In the case of
`.utility.annotations` those are, respectively:

 * zope.security.interfaces.IPrincipal
 * zope.annotation.interfaces.IAnnotations

As can be seen here:

https://github.com/zopefoundation/zope.principalannotation/blob/master/src/zope/principalannotation/utility.py#L122-L126

The second <adapter /> element creates a multi-adapter from (IPrincipal,
Interface) to IAnnotations.

So I tried fixing it.
>
>   <adapter
>       factory=".utility.annotations"
>       provides="zope.annotation.interfaces.IAnnotations"
>       for="zope.principalregistry.principalregistry.Principal"
>       />
>
> No luck.  I still get the following error report.  Cannot adapt.
>
>   File "/root/.buildout/eggs/zope.app.container-3.9.2-py2.7.egg/
> zope/app/container/browser/contents.py", line 462, in
> getPrincipalClipboard
>     annotations = IAnnotations(user)
> TypeError: ('Could not adapt', <zope.principalregistry.principalregistry.Principal
> object at 0x80bae03d0>, <InterfaceClass zope.annotation.interfaces.
> IAnnotations>)
>
> I am running the most recent release of grok, to which I added
>
> zope.principalannotation.
>
>
> I am trying to adapt the user object.
> (Pdb) user
> <zope.principalregistry.principalregistry.Principal object at 0x80bae03d0>
>
>
> Here is what I have tried so far.
>
> Maybe I am not installing it correctly. So I inserted a typo in the
> principalannotation configuration file, and sure enough I got an error
> report
>
>
> So let me see if the adapter is loaded.
>
>
> (Pdb) from zope.component import getGlobalSiteManager
> (Pdb) gsm = getGlobalSiteManager()
> (Pdb) gsm.adapters._adapters
>
> A long list is returned, but searching on
> zope.annotation.interfaces.IAnnotations
> gives me
>
> <implementedBy zope.principalregistry.principalregistry.Principal>:
> {<InterfaceClass zope.annotation.interfaces.IAnnotations\
> >: {u'': <function annotations at 0x80b983230>}},
>
> Okay, so it is in the list of adapters, but getAdapter seems to have a
> problem.
>
>
> (Pdb)  from zope.component import getAdapter
> (Pdb) from zope.annotation.interfaces  import IAnnotations
>
> (Pdb) getAdapter(user,IAnnotations)
> *** ComponentLookupError: (<zope.principalregistry.principalregistry.Principal
> object at 0x80bae03d0>, <InterfaceClass zope.annotation.interfaces.IAnnotations>,
> u'')
>
>
In the code I linked above, the adapter factory tries to look up a
`IPrincipalAnnotationUtility` (while ignoring the context parameter, which
is bad form, but likely not the cause of your troubles).

Maybe you're getting the adaptation error because you don't have an
`IPrincipalAnnotationUtilty` utility?


>
> For those interested in the context, I am trying to put up a Zope 2 style
> ZMI on top of grok. For the cut copy paste interface, it needs to store the
> objects somewhere, presumably on the principal, but since principals are
> transient objects, the principal annotation package  stores the data
> persistently.
>
> I am not sure what to try next.  Any advice would be most appreciated.
>

For this immediate problem, perhaps you need to register an
`IPrincipalAnnotationUtility`. The file I linked above contains a
persistent implementation, suitable registration on a local site manager.
"persistent" means it won't be there by default until you actually register
it.

For the more generic problem of a Zope2 like management interface on top of
ZODB storage containing a copy+paste implementation, done on modern
libraries (including a zca registry), you could try SubstanceD:

http://substanced.readthedocs.org/

Cheers,

Leo



>
> Christopher Lozinski
>
>
>
> _______________________________________________
> Zope-Dev maillist  -  Zope-Dev at zope.org
> https://mail.zope.org/mailman/listinfo/zope-dev
> **  No cross posts or HTML encoding!  **
> (Related lists -
> https://mail.zope.org/mailman/listinfo/zope-announce
> https://mail.zope.org/mailman/listinfo/zope )
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.zope.org/pipermail/zope-dev/attachments/20140609/7a191996/attachment.html>


More information about the Zope-Dev mailing list