Skip to content

Commit

Permalink
Merge pull request etianen#946 from etianen/revert-fix
Browse files Browse the repository at this point in the history
Handling case of missing object in admin revert
  • Loading branch information
etianen authored Sep 19, 2023
2 parents 3d95952 + b88a15c commit f84a31c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion reversion/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,14 @@ def _reversion_revisionform_view(self, request, version, template_name, extra_co
set_comment(_("Reverted to previous version, saved on %(datetime)s") % {
"datetime": localize(template_localtime(version.revision.date_created)),
})
else:
elif response.status_code == 200:
response.template_name = template_name # Set the template name to the correct template.
response.render() # Eagerly render the response, so it's using the latest version.
raise _RollBackRevisionView(response) # Raise exception to undo the transaction and revision.
else:
raise RevertError(_("Could not load %(object_repr)s version - not found") % {
"object_repr": self.object_repr,
})
except (RevertError, models.ProtectedError) as ex:
opts = self.model._meta
messages.error(request, force_str(ex))
Expand Down

0 comments on commit f84a31c

Please sign in to comment.