﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
9964	Transaction middleware closes the transaction only when it's marked as dirty	ishirav	Malcolm Tredinnick	"The transaction middleware commits only dirty transactions on success, and rolls back only dirty transactions in case of an error.

This means that any transaction that only SELECTs data gets rolled back (I'm not sure by whom - the database itself, perhaps?). So this is what I see in my PostgreSQL log:

{{{
BEGIN; SET TRANSACTION ISOLATION LEVEL READ COMMITTED
SET TIME ZONE E'America/Chicago'
SELECT ...
SELECT ...
SELECT ...
ROLLBACK
}}}

The expected behavior is a COMMIT (except in case of an error). 

Typically this does not cause any problems, because it affects only non-dirty transactions.

However if you use raw SQL to make database modifications, it will be rolled back unless the dirty flag gets set by some another part of your code. This can result in loss of data, and a very hard to find bug...

The correct behavior would be to always close the transaction, regardless of the dirty flag. Meaning that TransactionMiddleware.process_response should always call transaction.commit(), and TransactionMiddleware.process_exception should always call transaction.rollback()

This bug is also the cause of tickets #9763 and #9919
"	Uncategorized	closed	Database layer (models, ORM)	1.0-beta	Normal	fixed	transactions	jdunck@… Carl Meyer Sebastian Rahlf Shai Berger Forest Bond Peter Bengtsson xof Andrii Kurinnyi Dan Fairs Brodie Rao	Ready for checkin	1	0	0	0	0	0
