Plone upgrade – Clear and Rebuild failed

Plone is not working very well when portal_catalog is not up-to-date. This happens after upgrades. It is recommended to go to portal_catalog, section Advanced and run: Clear and Rebuild.

I did this, but after few seconds I’ve got this fancy error:

Module ZPublisher.Publish, line 126, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 46, in call_object
Module Products.CMFPlone.CatalogTool, line 460, in manage_catalogRebuild
Module plone.app.discussion.patches, line 45, in patchedClearFindAndRebuild
Module Products.ZCatalog.ZCatalog, line 287, in manage_catalogClear
Module Products.ZCatalog.Catalog, line 102, in clear

If you dig deep down into ZCatalog code, then you’ll see that some objects in DB simply don’t have clear method. Those objects are typically some ancient instances of TextIndex or instance of some long dead product.

Solution is to catch this error and remove those old grumpy objects from DB. Here is small patch:
eggs/Products.ZCatalog-2.13.23-py2.7.egg/Products/ZCatalog/Catalog.py:

    def clear(self):
        """ clear catalog """

        self.data = IOBTree()  # mapping of rid to meta_data
        self.uids = OIBTree()  # mapping of uid to rid
        self.paths = IOBTree()  # mapping of rid to uid
        self._length = BTrees.Length.Length()
        to_delete = []

        for index in self.indexes.keys():
            try:
                self.getIndex(index).clear()
            except:
                LOG.error('unclearable object %s. ' % str(index))
                to_delete.append(index)

        for del_index in to_delete:
            LOG.error('Removing from index %s. ' % str(del_index))
            del self.indexes[del_index]

Remove eggs/Products.ZCatalog-2.13.23-py2.7.egg/Products/ZCatalog/Catalog.pyc file to avoid caching. Start the Plone and run Clear and Rebuild function. Watch log file also for error messages from ZCatalog.

No votes yet.
Please wait...

Leave a comment

29. September 2012 at 20:37 - Software engineering (Tags: , , , , , ). Both comments and pings are currently closed.

Comments are closed.