Hi All,
I have ATOMIC_REQUESTS set to True in my database configuration:
'ENGINE': 'django.db.backends.postgresql_psycopg2',
But I started getting the following error when attempting to use select_for_update() in one particular view:
select_for_update cannot be used outside of a transaction.
As the error suggests, it turns out that database queries inside this particular view are not executing inside a transaction, even though ATOMIC_REQUESTS is set to True. I tested this essentially by performing an insert within the same view and then throwing an exception -- the change was indeed committed.
I'm not sure why this is occurring. Other views in my application respect the ATOMIC_REQUESTS setting, and I'm able to use select_for_update() successfully elsewhere. There is nothing special about this particular view that I can see. It's just processing a form and inserting some records. I can paste the view code if it helps, but there is really nothing remarkable about it, which leads me to believe that the problem lies elsewhere.
I have no idea how to debug this. I would like all requests in my application to be wrapped in transactions, as indicated by the ATOMIC_REQUESTS setting. Any help is appreciated.
Thanks.