SQL panel should track transactions #89

lamby opened this Issue Jul 21, 2010 · 2 comments


None yet
3 participants

lamby commented Jul 21, 2010

I often need to know exactly where we are committing inside a Django view. I've got this working with http://gist.github.com/484450

(Unfortunately, commit() and rollback() are methods of the database connection, not the cursor so we have to track them slightly differently.)


aaugustin commented Oct 18, 2013

In Django < 1.6, without the TransactionMiddleware, this would result in some noise: every write query would be followed by a commit. At least it would have a cathartic value by helping people realize how weird transaction management was :)

As of Django 1.6, the situation is going to get slightly more complicated, because Django will use database-level autocommit by default. As a consequence, you cannot assume that every database query starts a transaction anymore.

Transactions are started by turning autocommit off. You can check the value of connection.get_autocommit() to tell whether a transaction is in progress.

SQLite is special. Transactions are started by executing a begin statement, which will show up in the SQL panel. However, connection.get_autocommit() works too.

You still have to instrument commit and rollback to distinguish two consecutive transactions from a single transaction.

Another idea would be to instrument the atomic decorator / context manager. Then we could show nested transactions with indentation.

All this means that it's going to be difficult to support Django < 1.6 and >= 1.6 at the same time.

This is the end of my brain dump, I hope it helps.


matthiask commented Aug 19, 2016

Luckily we don't support Django <1.6 anymore, so maybe, if anyone wants to tackle this...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment