Plone技术资料

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1976|回复: 0

Plone错误解读:AttributeError: type object 'ISalt' has no attribute '__iro__'

[复制链接]
发表于 2019-8-2 16:36:47 | 显示全部楼层 |阅读模式
PurposeOccasionally you’ll download and install a product in Plone that uses local persistent utilities.This usually seems pretty innocent in itself; however, it sometimes happens that when you uninstall the product and remove its egg from the file system, the utility is still registered.This will essentially break your instance unless you make the egg available again so the ZODB can reference the utilities during lookups.This how-to will explain how to remove these utilities manually.

SymptomsYou’ll find zope throwing errors like this,
  1. AttributeError: type object 'IATCTTool' has no attribute '__iro__'
复制代码

PrerequisitesYou will need appropriate access to the zope server in order to run the site in debug mode.

Step by stepFirst off, fire up the instance in debug mode
  1. bin/instance debug
复制代码
Get the site manager for your Plone instance. ‘app’ references the zope root.
  1. sm = app.Plone.getSiteManager()
复制代码
Then you’ll want to import the guilty utility’s interface, unregister it and delete it. It should look somethings like this:
  1. from collective.product.interfaces import IUtility, INamedUtility

  2. # for unnamed utility
  3. util = sm.getUtility(IUtility)
  4. sm.unregisterUtility(IUtility)
  5. del util
  6. sm.utilities.unsubscribe((), IUtility)
  7. del sm.utilities.__dict__['_provided'][IUtility]
  8. del sm.utilities._subscribers[0][IUtility]

  9. #also for named utility
  10. util = sm.queryUtility(INamedUtility, name='utility-name')
  11. sm.unregisterUtility(util, INamedUtility, name='utility-name')
  12. del util
  13. del sm.utilities._subscribers[0][INamedUtility]
复制代码
Now you need to commit your changes to the ZODB.
  1. import transaction
  2. transaction.commit()
  3. app._p_jar.sync()
复制代码

An ExampleI found myself in this situation with the Singing and Dancing product so I’ll just go through the code here to fix both a normal utility and named utility found in it.
  1. from collective.singing.interfaces import ISalt
  2. from collective.singing.async import IQueue
  3. import transaction

  4. portal = app.Plone
  5. sm = portal.getSiteManager()

  6. util_obj = sm.getUtility(ISalt)
  7. sm.unregisterUtility(provided=ISalt)
  8. del util_obj
  9. sm.utilities.unsubscribe((), ISalt)
  10. del sm.utilities.__dict__['_provided'][ISalt]
  11. del sm.utilities._subscribers[0][ISalt]

  12. util = sm.queryUtility(IQueue, name='collective.dancing.jobs')
  13. sm.unregisterUtility(util, IQueue, name='collective.dancing.jobs')
  14. del util
  15. del sm.utilities._subscribers[0][IQueue]
  16. Handling subscribers, adapters and utilities
  17. sm = app.myportal.getSiteManager()
  18. adapters = sm.utilities._adapters
  19. for x in adapters[0].keys():
  20.     if x.__module__.find("collective.myproduct") != -1:
  21.       print "deleting %s" % x
  22.       del adapters[0][x]
  23. sm.utilities._adapters = adapters

  24. subscribers = sm.utilities._subscribers
  25. for x in subscribers[0].keys():
  26.     if x.__module__.find("collective.myproduct") != -1:
  27.       print "deleting %s" % x
  28.       del subscribers[0][x]
  29. sm.utilities._subscribers = subscribers

  30. provided = sm.utilities._provided
  31. for x in provided.keys():
  32.     if x.__module__.find("collective.myproduct") != -1:
  33.       print "deleting %s" % x
  34.       del provided[x]
  35. sm.utilities._provided = provided

  36. from transaction import commit
  37. commit()
  38. app._p_jar.sync()
复制代码

Removing portal toolsIf you still have problems (re)installing products after you removed the broken local persistent components, you probably have to clean the Portal setup tool.You probably see something like this in the error log :
  1. setup_tool = app.myportal.portal_setup
  2. toolset = setup_tool.getToolsetRegistry()
  3. if 'portal_myproduct' in toolset._required.keys():
  4.     del toolset._required['portal_myproduct']
  5.     setup_tool._toolset_registry = toolset

  6. from transaction import commit
  7. commit()
  8. app._p_jar.sync()
复制代码

ReferencesI didn’t by any means figure this all our on my own so please do not give me credit for it. Actually, most of this is shamelessly stolen. Thanks for the original fixers of the problem! Here are my references:







回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|Plone技术资料 ( 湘ICP备14006519号-1 )

GMT+8, 2019-10-22 12:36 , Processed in 0.044962 second(s), 14 queries , Gzip On.

Powered by Plone! X3.4

© 2001-2019 Plone.org.

快速回复 返回顶部 返回列表