django-debug-toolbar
django-debug-toolbar copied to clipboard
SQL panel should track transactions
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.)
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.
Luckily we don't support Django <1.6 anymore, so maybe, if anyone wants to tackle this...
Any further thoughts on this folks?
Oh, I'd certainly review a pull request adding this feature. It's not a thing which bothers me right now though.
Not much changed since 5 years ago ;-)
Any movement on this? Seeing transaction data in the SQL panel would be very helpful.
I'm not aware of any work happening in this area right now. Nothing has changed...