Threaded Django task doesn't automatically handle transactions or db connections?
- by Gabriel Hurley
I've got Django set up to run some recurring tasks in their own threads, and I noticed that they were always leaving behind unfinished database connection processes (pgsql "Idle In Transaction").
I looked through the Postgres logs and found that the transactions weren't being completed (no ROLLBACK). I tried using the various transaction decorators on my functions, no luck.
I switched to manual transaction management and did the rollback manually, that worked, but still left the processes as "Idle".
So then I called connection.close(), and all is well.
But I'm left wondering, why doesn't Django's typical transaction and connection management work for these threaded tasks that are being spawned from the main Django thread?