Re[2]: [Zope-CMF] Setting local role programmatically

Dieter Maurer dieter@handshake.de
Mon, 12 Aug 2002 20:49:56 +0200


Rainer Thaden writes:
 > ...
 > def setOwnerToLocalRoleManager(sci):
 >     obj=sci.object;
 >     userid = obj.getOwner().getId()
 >     obj.manage_setLocalRoles(obj, userid, 'Manager')
 > ...
 > Error Type: AttributeError 
 > Error Value: __hash__
 > 
 > ...
 >   File C:\Programme\Zope\lib\python\AccessControl\Role.py, line 352, in manage_setLocalRoles
 >     (Object: ohrnah)
 > AttributeError: (see above)
 > 
 > The error happens here in dict[userid]=roles
 > 
 >     def manage_setLocalRoles(self, userid, roles, REQUEST=None):
 >         """Set local roles for a user."""
 >         if not roles:
 >             raise ValueError, 'One or more roles must be given!'
 >         dict=self.__ac_local_roles__ or {}
 >         dict[userid]=roles
 >         self.__ac_local_roles__=dict
 >         if REQUEST is not None:
 >             stat='Your changes have been saved.'
 >             return self.manage_listLocalRoles(self, REQUEST, stat=stat)
 > ...
"userid" is apparently not hashable.
I do not see why.

Maybe, you start debugging.
You can put a "import pdb; pdb.set_trace()" in your
"setOwnerToLocalRoleManager". Zope will stop when it reaches this
line and enter "pdb" (the Python debugger, described in the Python
library reference).

By the way, the third argument to "manage_setLocalRoles" almost surely
needs to be a sequence, i.e. "('Manager',)" instead of "Manager".
This is not your current problem, but it would be the next one...


Dieter