Hi,
I have a model (my_model) with foreignkeys with "on_delete" set to "models.PROTECT".
my_link = models.ForeignKey(my_other_model, on_delete=models.PROTECT, null=True, blank=True)
If I create a my_model and dont set my_link, then reversion works fine.
But if I set my_link to actually link to an instance of my_other_model then I get the following error when I try to look at a reversion history instance in the admin view.
E.g going to:
http://127.0.0.1:8000/admin/my_app/my_model/1/history/1/
gives:
Internal Server Error: /admin/my_app/organism/1/history/1/
Traceback (most recent call last):
File "/home/my_user/.pyenv/versions/3.8.0/envs/ve38/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/my_user/.pyenv/versions/3.8.0/envs/ve38/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/my_user/.pyenv/versions/3.8.0/envs/ve38/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/my_user/.pyenv/versions/3.8.0/envs/ve38/lib/python3.8/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/my_user/.pyenv/versions/3.8.0/envs/ve38/lib/python3.8/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/home/my_user/.pyenv/versions/3.8.0/envs/ve38/lib/python3.8/site-packages/django/contrib/admin/sites.py", line 231, in inner
return view(request, *args, **kwargs)
File "/home/my_user/.pyenv/versions/3.8.0/envs/ve38/lib/python3.8/site-packages/reversion/admin.py", line 214, in revision_view
return self._reversion_revisionform_view(
File "/home/my_user/.pyenv/versions/3.8.0/envs/ve38/lib/python3.8/site-packages/reversion/admin.py", line 164, in _reversion_revisionform_view
version.revision.revert(delete=True)
File "/home/my_user/.pyenv/versions/3.8.0/envs/ve38/lib/python3.8/site-packages/reversion/models.py", line 101, in revert
collector.collect(list(group))
File "/home/my_user/.pyenv/versions/3.8.0/envs/ve38/lib/python3.8/site-packages/django/db/models/deletion.py", line 245, in collect
field.remote_field.on_delete(self, field, sub_objs, self.using)
File "/home/my_user/.pyenv/versions/3.8.0/envs/ve38/lib/python3.8/site-packages/django/db/models/deletion.py", line 23, in PROTECT
raise ProtectedError(
django.db.models.deletion.ProtectedError: ("Cannot delete some instances of model 'my_other_model' because they are referenced through a protected foreign key: 'my_model.mylink'", <QuerySet [<my_model: my_model_string>]>)
"GET /admin/my_app/organism/1/history/1/ HTTP/1.1" 500 121554
It would appear the offending part is when reversion tries to : "# Delete objects that are no longer in the current revision."