我有一个将成员添加到组的处理程序。此处理程序的最后一行导致错误:
TypeError: Can't pickle objects in acquisition wrappers.
> /home/mnieber/.buildout/eggs/ZODB3-3.10.3-py2.6-linux-i686.egg/ZODB/serialize.py(431)_dump()
430 self._p.dump(classmeta)
--> 431 self._p.dump(state)
432 self._file.truncate()
在 pdb 调试器中,我可以看到确实 Plone 正在尝试腌制一个作为 Acquisition 包装器的值:
ipdb> state
((((<PloneUser 'newuser@usecm.com'>, ('Default_Group',), 'maarten@usecm.com', ('PAS',)),),),)
ipdb> type(state[0][0][0][0])
<type 'Acquisition.ImplicitAcquisitionWrapper'>
但是,我看不到哪个对象正在被腌制,因此我不知道我的代码的哪一部分需要修复。我的问题是:我应该如何调试这个错误?我尝试查看所有堆栈帧,但没有一个显示正在序列化的对象。
处理程序就是这个(run_insecure 是一个装饰器,我用它来临时安装一个新的安全管理器,以避免在添加新成员时出现 NotAuthorized 错误):
@adapter(IPrincipalCreatedEvent)
@run_insecure
def userCreatedHandler(event):
portal_groups = getToolByName(getSite(), "portal_groups")
membersGroup = portal_groups.getGroupById('Default_Group')
membersGroup.addMember(event.principal)
完整的错误是这个:
Traceback (innermost last):
Module ZPublisher.Publish, line 134, in publish
Module Zope2.App.startup, line 301, in commit
Module transaction._manager, line 89, in commit
Module transaction._transaction, line 329, in commit
Module transaction._transaction, line 443, in _commitResources
Module ZODB.Connection, line 567, in commit
Module ZODB.Connection, line 623, in _commit
Module ZODB.Connection, line 658, in _store_objects
Module ZODB.serialize, line 422, in serialize
Module ZODB.serialize, line 431, in _dump
TypeError: Can't pickle objects in acquisition wrappers.
> /home/mnieber/.buildout/eggs/ZODB3-3.10.3-py2.6-linux-i686.egg/ZODB/serialize.py(431)_dump()
430 self._p.dump(classmeta)
--> 431 self._p.dump(state)
432 self._file.truncate()