Using transactions

I have a colleague’s code I’m trying to test. We’re using playwright to do end-to-end tests.

He used functional views and transaction.atomic() blocks with the view ‘return JSONResponse()’ still inside the transaction block.

I’ve added some ‘transaction.commit()’ statements or moved the return statement outside the atomic block, with the positive effect that the database transaction rollbacks are happening cleanly and as a result the tests are less flakey.

My concern is that reading through the docs, what he did looks correct. The behaviour I’m seeing fits my mental model in which a test finishes with a transaction still pending, but maybe that’s not possible?