﻿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
6669	@transaction.commit_on_success does not rollback when it should	james@…	nobody	"I am using PostgresSQL and have a problem with code like this:

{{{
@transaction.commit_on_success
def create_system_user():
    user = User.objects.create_user(username='system', password='iamr00t', email='root@SITENAME.com')
    UserProfile.objects.create(user=user)

try:
    create_system_user()
except:
    pass

try:
    create_system_user()
except:
    pass

print User.objects.all()
}}}



the above code will give:

{{{
psycopg2.ProgrammingError: current transaction is aborted, commands ignored until end of transaction block
}}}


I have determined that adding a 
transaction.rollback()
before the 

{{{
print User.objects.all()
}}}

will allow the user list to be printed correctly.

Looking at the django code, I see:

{{{
            except Exception, e:
                if is_dirty():
                    rollback()
                raise
}}}



in commit_on_success. My guess is that is_dirty() does not take into consideration that an error in PostgresSQL will require a rollback before further work can continue.

"	Uncategorized	closed	Database layer (models, ORM)	dev	Normal	fixed	transaction, commit	Shai Berger bhuztez@… k@…	Accepted	1	0	0	0	0	0
