etianen/django-reversion — Issue #112: Retrieve the created revision
Author: SystemParadox
Created: 2011-12-05 10:19:23+00:00
State: open

Hi. I'm having trouble obtaining a created 'Revision' object for use with my undo system. I would like to obtain the reversion object for the operation that has just been performed. Something like this:

```python
with reversion.create_revision() as revision:
# do stuff
# add revision.id to the response for undo purposes
```

However, ReversionContext.__exit__() doesn't return anything and neither does RevisionContextManager.end().

I can't use reversion.get_for_object() because:
1. This part of the code is a generic action handler, and shouldn't need to know what models are being used.
2. It absolutely *must* be guaranteed to return the revision *for this transaction*, or None. I don't know how Django deals with concurrent requests, but I believe it may be possible (however unlikely) that another request may be served between 'this' transaction and retrieving the latest revision, in which case reversion.get_for_object() will return the revision for the other request instead of this one.

I've been playing with the reversion source for a while now in an effort to construct some sort of patch for this. I have two main issues at the moment:
1. The revision is not saved until the top of the stack is reached. I suspect that I will just have to make sure that I'm the outermost context in my setup.
2. RevisionContextManager.end() iterates a dictionary of managers/manager_contexts. I have only ever seen one of these used, that is the "default" one. What is the purpose of multiple RevisionManagers?

Any thoughts on this would be much appreciated.
Many thanks.

Simon