[Zope-dev] Re: manage_permission from script

Tres Seaver tseaver at zope.com
Thu Apr 8 10:55:51 EDT 2004


Erik A.Dahl wrote:
> Thanks for the suggestion but no joy here.  Here is the full trace...
> 
> Python 2.3.3 (#1, Jan 27 2004, 09:17:28)
> [GCC 3.2 20020903 (Red Hat Linux 8.0 3.2-7)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> import Zope
>  >>> app = Zope.app()
>  >>> app.testfolder
> <Folder instance at 410d9f50>
>  >>> tf = app.testfolder
>  >>> tf.getPhysicalRoot().manage_permission("View", ["Owner",])
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "/home/edahl/zope-2.7.0/lib/python/AccessControl/Role.py", line 
> 164, in manage_permission
>     for p in self.ac_inherited_permissions(1):
>   File "/home/edahl/zope-2.7.0/lib/python/AccessControl/Role.py", line 
> 82, in ac_inherited_permissions
>     for p in self._subobject_permissions():
>   File "/home/edahl/zope-2.7.0/lib/python/OFS/ObjectManager.py", line 
> 212, in _subobject_permissions
>     return (Products.__ac_permissions__+
> AttributeError: aq_acquire

'manage_permission' (really, the methods it calls) make the assumption 
(unwarranted in your case) that they are called on an 
acquisition-wrapped object.  In your case, the root object is *not* 
wrapped, and therefore does not have the 'aq_acquire' method.  Normally, 
when called via the publisher, the root object *is* wrapped (in a 
RequestContainer).

A workaround would be to wrap the root first:

  zopectl> debug
  Starting debugger (the name "app" is bound to the top-level Zope object)
  >>> app
  <Application instance at 40dc1bf0>
  >>> app.aq_chain  # not wrapped
  Traceback (most recent call last):
    File "<stdin>", line 1, in ?
  AttributeError: aq_chain
  >>> app.manage_addFolder( 'testfolder' )
  >>> tf = app.testfolder
  >>> pr = tf.getPhysicalRoot()
  >>> pr.aq_acquire
  Traceback (most recent call last):
    File "<stdin>", line 1, in ?
  AttributeError: aq_acquire
  >>> pr = pr.__of__(tf)
  >>> pr.aq_chain
  [<Application instance at 40dc1bf0>, <Folder instance at 40e51d10>, 
<Application instance at 40dc1bf0>]
  >>> pr.aq_acquire
  <CMethod object at 0x40dfac60>
  >>> manage_permission("View", ["Owner"])
  >>>

The real fix would be to rip out the use *anywhere* of 
'self.aq_acquire';  the 'aq_aquire' function from Acquisition will 
always do the Right Thing (TM) if the object is not yet wrapped (the 
difference parallels using 'aq_base', 'aq_parent', 'aq_inner' as 
functions rather than methods).

Tres.
-- 
===============================================================
Tres Seaver                                tseaver at zope.com
Zope Corporation      "Zope Dealers"       http://www.zope.com




More information about the Zope-Dev mailing list