Plone 如何修复zc.relation目录中的KeyError

Plone 如何修复zc.relation目录中的KeyError,plone,relationship,zodb,plone-4.x,Plone,Relationship,Zodb,Plone 4.x,我们的一个网站有一个坏的关系目录,我不知道如何修复它 这是我在日志中看到的: 2015-11-20T09:27:43错误Zope.SiteErrorLog 1448018863.240.913599974037http://www.example.com/folder/news-item/@@编辑 回溯(最里面的最后一个): 模块ZPublisher.Publish,第138行,在Publish中 模块ZPublisher.mapply,第77行,在mapply中 模块ZPublisher.Pu

我们的一个网站有一个坏的关系目录,我不知道如何修复它

这是我在日志中看到的:

2015-11-20T09:27:43错误Zope.SiteErrorLog 1448018863.240.913599974037http://www.example.com/folder/news-item/@@编辑
回溯(最里面的最后一个):
模块ZPublisher.Publish,第138行,在Publish中
模块ZPublisher.mapply,第77行,在mapply中
模块ZPublisher.Publish,第48行,在call_对象中
模块z3c.form.form,第218行,输入调用__
模块collective.nitf.browser,第64行,更新中
模块plone.dexterity.browser.edit,第62行,更新中
模块plone.z3cform.fieldsets.extensible,第59行,更新中
模块plone.z3cform.patch,第30行,在GroupForm_更新中
模块z3c.form.group,第145行,正在更新中
模块plone.app.z3cform.csrf,第21行,执行中
模块z3c.form.action,第98行,执行中
模块z3c.form.button,第315行,输入调用__
模块z3c.form.button,第170行,输入调用__
模块plone.dextrity.browser.edit,第26行,在HandLeappy中
模块z3c.form.group,第126行,在applyChanges中
模块zope.event,第31行,在notify中
模块zope.component.event,第24行,调度中
模块zope.component.\u api,第136行,在订阅服务器中
订阅服务器中的模块zope.component.registry,第321行
订阅服务器中的模块zope.interface.adapter,第585行
objectEventNotify中第32行的模块zope.component.event
模块zope.component.\u api,第136行,在订阅服务器中
订阅服务器中的模块zope.component.registry,第321行
订阅服务器中的模块zope.interface.adapter,第585行
updateRelations中第76行的模块z3c.relationfield.event
模块zc.relation.catalog,第546行,未索引
unindex_文档中模块zc.relation.catalog,第556行
模块zc.relation.catalog,第622行,in_移除
密钥错误:304600783
我已经在中尝试了几年前由@martijn pieters编写的代码,但似乎不再有效,因为我找不到任何名为
IComplexRelationshipContainer
的接口

有什么提示吗?

  • 验证是否安装了plone.relations

  • 看这里,可能是这个问题的解决方案

例如


我想几年前我也遇到过类似的事情

我启动了这个,之后一切正常:

    from Products.Five.browser import BrowserView
    from Products.CMFCore.utils import getToolByName
    from z3c.relationfield.event import updateRelations
    from z3c.relationfield.interfaces import IHasRelations
    from zc.relation.interfaces import ICatalog
    from zope.component import getUtility


    class View(BrowserView):
        def __call__(self):
            rcatalog = getUtility(ICatalog)
            # Clear the relation catalog to fix issues with interfaces that don't exist anymore.
            # This actually fixes the from_interfaces_flattened and to_interfaces_flattened indexes.
            rcatalog.clear()

            pc = getToolByName(self.context, 'portal_catalog')
            brains = pc.searchResults(object_provides=IHasRelations.__identifier__)
            for brain in brains:
                obj = brain.getObject()
                updateRelations(obj, None)
            return "Catalog rebuilt for %s objects" % len(brains)

这可能会帮助您:。它展示了如何在更新版本的plone中获得关系。您应该能够通过将其设置为
None
+来删除已断开的
RelationValue
,必要时通知目录关系已被删除。我以前尝试过该代码,但没有成功,它也失败了,还出现了一个错误。我不能告诉你这是否有效,因为@cleberjsantos已经修复了它。@cleberjsantos这里没有说明你是如何修复这个问题的。只运行上面的代码段和:1-在本例中,在z3c.relationfield版本0.6.3中,在第79行“addRelations(obj,event)”添加注释of event.py 2-使用目录的“clear”方法删除所有记录:catalog.clear()清除目录不会破坏内容的任何关系,并且在编辑和保存每个内容后,现在所有内容都会重新编制索引。
    from Products.Five.browser import BrowserView
    from Products.CMFCore.utils import getToolByName
    from z3c.relationfield.event import updateRelations
    from z3c.relationfield.interfaces import IHasRelations
    from zc.relation.interfaces import ICatalog
    from zope.component import getUtility


    class View(BrowserView):
        def __call__(self):
            rcatalog = getUtility(ICatalog)
            # Clear the relation catalog to fix issues with interfaces that don't exist anymore.
            # This actually fixes the from_interfaces_flattened and to_interfaces_flattened indexes.
            rcatalog.clear()

            pc = getToolByName(self.context, 'portal_catalog')
            brains = pc.searchResults(object_provides=IHasRelations.__identifier__)
            for brain in brains:
                obj = brain.getObject()
                updateRelations(obj, None)
            return "Catalog rebuilt for %s objects" % len(brains)