django-debug-toolbar icon indicating copy to clipboard operation
django-debug-toolbar copied to clipboard

SQL panel should track transactions

Open lamby opened this issue 15 years ago • 7 comments

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.)

lamby avatar Jul 21 '10 13:07 lamby

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.

aaugustin avatar Oct 18 '13 19:10 aaugustin

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

matthiask avatar Aug 19 '16 10:08 matthiask

Any further thoughts on this folks?

lamby avatar Aug 27 '18 07:08 lamby

Oh, I'd certainly review a pull request adding this feature. It's not a thing which bothers me right now though.

matthiask avatar Sep 14 '18 15:09 matthiask

Not much changed since 5 years ago ;-)

aaugustin avatar Sep 15 '18 18:09 aaugustin

Any movement on this? Seeing transaction data in the SQL panel would be very helpful.

crgwbr avatar Mar 07 '19 17:03 crgwbr

I'm not aware of any work happening in this area right now. Nothing has changed...

matthiask avatar Mar 07 '19 18:03 matthiask