Search code examples
plonezopezodb

Uncatalog objects that can not be found


I'm updating my Plone website from 4.2.x to 4.3.x and I'm getting quite a lot of errors like:

INFO plone.app.upgrade Reindex Description index with I18N Case Normalizer
ERROR Zope.ZCatalog reindexIndex could not resolve an object from the uid '/RANDOM/PATH'

Checking the website for that path indeed is not there anymore.

So how can one get rid of those objects before actually running the upgrade?

Or actually, given the upgrade method (https://github.com/plone/plone.app.upgrade/blob/master/plone/app/upgrade/v43/alphas.py#L56) which basically goes over all indexes on the catalog and then does the following:

catalog.manage_clearIndex([index_id])
catalog.reindexIndex(index_id,aq_get(context, 'REQUEST', None))

I don't need to do anything because the manage_clearIndex already removes everything and the reindexIndex only indexes the ones that can be found?


Solution

  • Seems that the problem is easier to solve than it seemed: you only need to uncatalog that object and that will be it.

    So for example this code will do it:

    catalog = getToolByName(context, 'portal_catalog')
    for brain in catalog(portal_type='Discussion Item'):
        try:
            comment = brain.getObject()
        except KeyError:
            catalog.uncatalog_object(brain.getPath())
    

    Source: http://docs.plone.org/develop/plone/searching_and_indexing/catalog.html