Search code examples
pythondjangotransactionsdjango-rest-frameworkdjango-database

In Django-Rest-Framework how can I make all requests, except GET, transactional?


According to Django's documentation I can set ATOMIC_REQUESTS to make all requests atomic. It also states that I'm able to selectively turn it off on a "per-View" basis, not "per-View-function".

But it isn't clear if the GET method would also be transactional. I understand that the REST definition considers this method as safe and idempotent, thus it shouldn't ever be transactional. Specially when you think about several GET requests unnecessarily overloading the database.

Finally, we're using a ListCreateView then we cannot make the entire view non-transactional and also we cannot create a separated view just for listing because that would hurt our URLs pattern.


Solution

  • Unfortunately it's not possible.