Closed PavelPancocha closed 1 year ago
Sorry it took me so long to get back to you. I've had a baby and it's taken up a lot of my time! 👶
Please take a look at #946 and let me know if it fixes your problem! ❤️
@etianen that should, I will test it when I will get to it. Thank you! Btw: Congratulations 🎉 👶🏻
Released as v5.0.5
What status code is given on error? Is it 404?
See discussion in #948
Hi! First thank you for all the work on this awesome tool.
We encountered one problem, that we think should be addressed directly in
django-reversion
:It is all about the "recover" view for a deleted object, let's take a look at this part: https://github.com/etianen/django-reversion/blob/master/reversion/admin.py#L169-L184
We do revert and get the response.
But which response? If you use the custom "get_queryset" it could happen, that you will not be able to get the given "restored" object. Why? There can be some different constraints that fire up when the transaction is committed, which doesn't happen here. But some other queries then can return "unexpected" results. Or expected, because in fact when the object would not be able to be committed, the query is also not able to return it. Let's show an example:
Eg. you can use
select_related
, which will try to do the select on the user:If it is reversible (no other admission for the given user and location exists):
When you commit the
ver.revision.revert(delete=True)
transaction, it will get processed.If it is not reversible (another admission for a given user and location exists):
When you commit the
ver.revision.revert(delete=True)
transaction, it will fail withIntegrityError
Back to our problem: If the object cannot be found (see above), Django will redirect you to
/admin/
with a user message that the given object does not exist. So the HttpResponse is not a response but HttpResponseRedirect, which cannot be rendered.I would propose to check the status code for the response and if it is not HTTP 200 (OK), raise
RevertError("Could not load %(object_repr)s version")
or similar.If this proposal is accepted, I can create a PR for this.
Thank you for your time and consideration.