diff --git a/.gitignore b/.gitignore index face70b8..636a599b 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,7 @@ Makefile .pydevproject .project .settings + +# virtual environment: +lib64 +pip-selfcheck.json diff --git a/sc/social/like/upgrades/v3046/__init__.py b/sc/social/like/upgrades/v3046/__init__.py index a0446220..4a08d7a0 100644 --- a/sc/social/like/upgrades/v3046/__init__.py +++ b/sc/social/like/upgrades/v3046/__init__.py @@ -5,6 +5,15 @@ import transaction +try: + # this exception must be resubmitted: + from ZODB.POSException import ConflictError +except ImportError: + # we don't really *require* this; + # if we don't have it, a dummy exception will do: + class ConflictError(Exception): + pass + def reindex_catalog(setup_tool): """Reindex objects to fix interfaces on the catalog.""" @@ -16,13 +25,24 @@ def reindex_catalog(setup_tool): results = catalog() logger.info(u'Found {0} objects'.format(len(results))) n = 0 + errors = 0 for obj in get_valid_objects(results): - catalog.catalog_object(obj, idxs=['object_provides'], update_metadata=False) + try: + catalog.catalog_object(obj, idxs=['object_provides'], update_metadata=False) + except ConflictError: + raise + except Exception as e: + errors += 1 + logger.error('{0!r} reindexing {1!r}'.format(e, obj)) + if test: + raise n += 1 if n % 1000 == 0 and not test: transaction.commit() logger.info('{0} items processed.'.format(n)) if not test: + if errors: + logger.info('{0} errors occured.'.format(errors)) transaction.commit() logger.info('Done.') diff --git a/sc/social/like/utils.py b/sc/social/like/utils.py index c011533b..f105e958 100644 --- a/sc/social/like/utils.py +++ b/sc/social/like/utils.py @@ -117,6 +117,8 @@ def get_valid_objects(brains): obj = b.getObject() except KeyError: obj = None + except AttributeError: + obj = None if obj is None: # warn on broken entries in the catalog msg = u'Skipping invalid reference in the catalog: {0}'