3

I want to start using django-reversion. It seems the easiest way is to use their middleware. But it gives the following warning:

Warning: Due to changes in the Django 1.6 transaction handling, revision data will be saved in a separate database transaction to the one used to save your models, even if you set ATOMIC_REQUESTS = True.

What are the caveats if the requests are not atomic? It seems to indicate that there might be some kind of race conditions. How could they look like? What do I need to watch out for?

Thank you for your time. Sorry for spelling mistakes I'm not a native speaker.

JasonTS
  • 2,479
  • 4
  • 32
  • 48

1 Answers1

2

As mentioned in the warning, due to some changes in the way django handles transactions since 1.6, the middlewares are no longer wrapped in the same transaction as the view function.

This is discussed at the following issue at django-reversion.

In practice, since the RevisionMiddleware runs outside of the transaction where the models are saved, no strict guarantee can be provided at the database level that reversion data will also be saved.

The usage of RevisionMiddleware was then discouraged. The following practice is advised:

If you need to ensure that your models and revisions are saved in the save transaction, please use the reversion.create_revision() context manager or decorator in combination with transaction.atomic()

This way, you can be sure that reversion_data will always be saved alongside model data. I hope this helps.

press_f5
  • 21
  • 5