Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log errors and proceed when reindexing #172

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ Makefile
.pydevproject
.project
.settings

# virtual environment:
lib64
pip-selfcheck.json
22 changes: 21 additions & 1 deletion sc/social/like/upgrades/v3046/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@

import transaction

try:
# this exception must be resubmitted:
from ZODB.POSException import ConflictError
except:
# 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."""
Expand All @@ -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 as e:
raise
except Exception as e:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a good idea; if you don't know what other exception can be raised here, better to remove this also or we can hide some other issues.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this operation be better atomic? The only improvement that could be made is to log the object that failed but raise the exception right away. If the upgrade runs without error, many users may think that everything went well when it didn't.

errors += 1
logger.error('%(e)r reindexing %(obj)r', locals())
tobiasherp marked this conversation as resolved.
Show resolved Hide resolved
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('%(errors)d errors occured.', locals())
transaction.commit()
logger.info('Done.')