isawnyu / pleiades-gazetteer

This repository provides a home for tickets and other planning documents for the Pleiades gazetteer of ancient places. Code is kept in multiple other repositories.
https://pleiades.stoa.org
11 stars 0 forks source link

reindexing object from script throws ComponentLookupError #338

Closed paregorios closed 6 years ago

paregorios commented 6 years ago
Traceback (most recent call last):
  File "/Users/paregorios/Documents/files/P/pleiades-buildout/pleiades3-buildout/parts/instance/bin/interpreter", line 329, in <module>
    exec _val
  File "<string>", line 1, in <module>
  File "scripts/reindex_wikipedia.py", line 43, in <module>
    catalog.catalog_object(ob, idxs=['SearchableText'])
  File "/Users/paregorios/Documents/files/P/pleiades-buildout/pleiades3-buildout/eggs/Products.CMFPlone-4.3.10-py2.7.egg/Products/CMFPlone/CatalogTool.py", line 349, in catalog_object
    update_metadata, pghandler=pghandler)
  File "/Users/paregorios/Documents/files/P/pleiades-buildout/pleiades3-buildout/eggs/Products.ZCatalog-3.0.2-py2.7.egg/Products/ZCatalog/ZCatalog.py", line 476, in catalog_object
    update_metadata=update_metadata)
  File "/Users/paregorios/Documents/files/P/pleiades-buildout/pleiades3-buildout/eggs/Products.ZCatalog-3.0.2-py2.7.egg/Products/ZCatalog/Catalog.py", line 347, in catalogObject
    self.updateMetadata(object, uid, index)
  File "/Users/paregorios/Documents/files/P/pleiades-buildout/pleiades3-buildout/eggs/Products.ZCatalog-3.0.2-py2.7.egg/Products/ZCatalog/Catalog.py", line 292, in updateMetadata
    newDataRecord = self.recordify(object)
  File "/Users/paregorios/Documents/files/P/pleiades-buildout/pleiades3-buildout/eggs/Products.ZCatalog-3.0.2-py2.7.egg/Products/ZCatalog/Catalog.py", line 415, in recordify
    attr = attr()
  File "/Users/paregorios/Documents/files/P/pleiades-buildout/pleiades3-buildout/src/Products.PleiadesEntity/Products/PleiadesEntity/content/Temporal.py", line 88, in getTimePeriods
    return [a['timePeriod'] for a in self.getSortedTemporalAttestations()]
  File "/Users/paregorios/Documents/files/P/pleiades-buildout/pleiades3-buildout/src/Products.PleiadesEntity/Products/PleiadesEntity/content/Temporal.py", line 76, in getSortedTemporalAttestations
    time_periods = get_vocabulary('time_periods')
  File "/Users/paregorios/Documents/files/P/pleiades-buildout/pleiades3-buildout/src/pleiades.vocabularies/pleiades/vocabularies/vocabularies.py", line 48, in get_vocabulary
    registry = getUtility(IRegistry)
  File "/Users/paregorios/Documents/files/P/pleiades-buildout/pleiades3-buildout/eggs/zope.component-3.9.5-py2.7.egg/zope/component/_api.py", line 169, in getUtility
    raise ComponentLookupError(interface, name)
zope.component.interfaces.ComponentLookupError: (<InterfaceClass plone.registry.interfaces.IRegistry>, '')
davisagli commented 6 years ago

How are you invoking the script?

paregorios commented 6 years ago
bin/instance run scripts/foobar_indexer.py

It does something like:

catalog = app.plone.portal_catalog
for b in catalog.unrestrictedSearchResults(portal_type='Place'):
    ob = b._unrestrictedGetObject()
    # do something to determine whether to reindex or not
    ob.reindexObject()
davisagli commented 6 years ago

It should work if you do bin/instance -Oplone run scripts/foobar_indexer.py. That'll make sure that plone is activated as the site to use for Zope component loookups.

My scripts to reindex often end up looking like this to make sure that it commits periodically rather than ending up with a giant long-running transaction that is more likely to conflict with other transactions:

import transaction
catalog = app.plone.portal_catalog
i = 0
for b in catalog.unrestrictedSearchResults(portal_type='Place'):
    ob = b._unrestrictedGetObject()
    # do something to determine whether to reindex or not
    ob.reindexObject()
    i += 1
    if not i % 200:
        print i
        transaction.commit()
transaction.commit()
paregorios commented 6 years ago

@davisagli thanks for the tip. That's got it!