2015-11-20 63 views
3

我們的一個網站有一個關係錯誤的目錄,我不知道如何解決它。如何修復zc.relation目錄中的KeyError

這是我在日誌中看到:

2015-11-20T09:27:43 ERROR Zope.SiteErrorLog 1448018863.240.913599974037 http://www.example.com/folder/news-item/@@edit 
Traceback (innermost last): 
    Module ZPublisher.Publish, line 138, in publish 
    Module ZPublisher.mapply, line 77, in mapply 
    Module ZPublisher.Publish, line 48, in call_object 
    Module z3c.form.form, line 218, in __call__ 
    Module collective.nitf.browser, line 64, in update 
    Module plone.dexterity.browser.edit, line 62, in update 
    Module plone.z3cform.fieldsets.extensible, line 59, in update 
    Module plone.z3cform.patch, line 30, in GroupForm_update 
    Module z3c.form.group, line 145, in update 
    Module plone.app.z3cform.csrf, line 21, in execute 
    Module z3c.form.action, line 98, in execute 
    Module z3c.form.button, line 315, in __call__ 
    Module z3c.form.button, line 170, in __call__ 
    Module plone.dexterity.browser.edit, line 26, in handleApply 
    Module z3c.form.group, line 126, in applyChanges 
    Module zope.event, line 31, in notify 
    Module zope.component.event, line 24, in dispatch 
    Module zope.component._api, line 136, in subscribers 
    Module zope.component.registry, line 321, in subscribers 
    Module zope.interface.adapter, line 585, in subscribers 
    Module zope.component.event, line 32, in objectEventNotify 
    Module zope.component._api, line 136, in subscribers 
    Module zope.component.registry, line 321, in subscribers 
    Module zope.interface.adapter, line 585, in subscribers 
    Module z3c.relationfield.event, line 76, in updateRelations 
    Module zc.relation.catalog, line 546, in unindex 
    Module zc.relation.catalog, line 556, in unindex_doc 
    Module zc.relation.catalog, line 622, in _remove 
KeyError: 304600783 

我已經嘗試過在The dreaded plone.relations IntId KeyError代碼,若干年前由@馬亭 - PIETERS寫的,但似乎已不再有效,因爲我無法找到任何名爲IComplexRelationshipContainer的接口。

任何提示?

+0

這可以幫助你:http://stackoverflow.com/questions/20290361/how-to-clean-up-old-interfaces-on- ZC-關係型錄。它展示瞭如何在更新版本的plone中獲得關係。如果需要,您應該能夠通過將「RelationValue」設置爲「None」來通知目錄,以確定關係已被刪除。 – Mathias

+0

我之前沒有運氣就試過這個代碼,它也失敗了。 – hvelarde

回答

1

例如,

from zope.component.hooks import setSite 
from AccessControl.SecurityManagement import newSecurityManager 
from AccessControl.SecurityManager import setSecurityPolicy 
from Testing.makerequest import makerequest 
from Products.CMFCore.tests.base.security import PermissiveSecurityPolicy, OmnipotentUser 
from zope.component import getUtility 
from zope.intid.interfaces import IIntIds 
from zc.relation.interfaces import ICatalog 
_policy=PermissiveSecurityPolicy() 
_oldpolicy=setSecurityPolicy(_policy) 
newSecurityManager(None, OmnipotentUser().__of__(app.acl_users)) 

portal = makerequest(app['Plone']) 
setSite(portal) 

intids = getUtility(IIntIds) 
catalog = getUtility(ICatalog) 

print [x.from_object for x in sorted(catalog.findRelations({}))] 
+0

@cleberjsantos你在這裏沒有展示你如何解決這個問題。 – hvelarde

+0

僅運行該代碼段的上方和: 1-在這種情況下,在z3c.relationfield版本0.6.3在行添加的event.py 2- 79「addRelations(OBJ,事件)」的註釋使用目錄的「清除」方法刪除所有記錄:catalog.clear() 清除目錄並沒有破壞內容的任何關係,並且在每個內容被編輯並再次保存後,所有內容都將重新編制索引。 –

1

我想在幾年前,我st upon了一些類似的東西。

我發起這個和後來的一切運行良好:

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) 
+0

因爲@cleberjsantos已經解決了這個問題,所以我不能告訴你它是否有效。 – hvelarde

相關問題