Skip to content

Commit

Permalink
_safe_revert: Add a logging traceback for IntegrityError
Browse files Browse the repository at this point in the history
This will be helpful @reversion.register users that explicitly declare
their fields.

Fixes #750
  • Loading branch information
tony committed Sep 25, 2022
1 parent 284dd51 commit dd78a1c
Showing 1 changed file with 5 additions and 0 deletions.
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.exception('Could not revert to {version}')
unreverted_versions.append(version)
if len(unreverted_versions) == len(versions):
raise RevertError(gettext("Could not save %(object_repr)s version - missing dependency.") % {
Expand Down

0 comments on commit dd78a1c

Please sign in to comment.