Reputation: 2568
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?
Upvotes: 1
Views: 641
Reputation: 2365
For these kinds of situations, collective.catalogcleanup may be nice.
Upvotes: 1
Reputation: 2876
I just ran into this, but it was a little bit more complicated as the error was showing up only when using sort_on='getObjPositionInParent'
on the catalog query.
I ended up by parsing the exception message and removing the offending brains from the catalog using this code:
while True:
try:
results = catalog(path='/Plone/foo', sort_on='getObjPositionInParent')
except ValueError as e:
id_ = e.message.split('"')[1]
results = catalog(id=id_)
print 'uncatalogging: {0} ({1} objects)'.format(id_, len(results))
[catalog.uncatalog_object(b.getPath()) for b in results]
else:
print 'done!'
break
It took some time but at the end I was able to clean the catalog.
Upvotes: 0
Reputation: 2568
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
Upvotes: 2