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

_safe_revert: Add a logging statement for IntegrityError #921

Merged
merged 2 commits into from
Oct 2, 2022
Merged
Changes from all 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
5 changes: 5 additions & 0 deletions reversion/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections import defaultdict
from itertools import chain, groupby
import logging

import django
from django.apps import apps
Expand All @@ -22,13 +23,17 @@
_get_content_type, _get_options)


logger = logging.getLogger(__name__)


def _safe_revert(versions):
unreverted_versions = []
for version in versions:
try:
with transaction.atomic(using=version.db):
version.revert()
except (IntegrityError, ObjectDoesNotExist):
logger.warning('Could not revert to {version}', exc_info=True)
unreverted_versions.append(version)
if len(unreverted_versions) == len(versions):
raise RevertError(gettext("Could not save %(object_repr)s version - missing dependency.") % {
Expand Down