﻿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
26340	Cannot rollback to a savepoint explicitly after an IntegrityError when autocommit is disabled	Aymeric Augustin	nobody	"I think the following code should work. Currently it crashes. (I haven't investigated the ramifications yet.)

{{{
>>> transaction.set_autocommit(False)
>>> sid = transaction.savepoint()
>>> User.objects.create(username='foobar')
<User: foobar>
>>> try:
...     User.objects.create(username='foobar')
... except IntegrityError:
...     print(""duplicate"")
... 
duplicate
>>> transaction.savepoint_rollback(sid)
Traceback (most recent call last):
  File ""$VIRTUAL_ENV/lib/python3.5/site-packages/django/core/management/commands/shell.py"", line 69, in handle
    self.run_shell(shell=options['interface'])
  File ""$VIRTUAL_ENV/lib/python3.5/site-packages/django/core/management/commands/shell.py"", line 61, in run_shell
    raise ImportError
ImportError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ""<console>"", line 1, in <module>
  File ""$VIRTUAL_ENV/lib/python3.5/site-packages/django/db/transaction.py"", line 66, in savepoint_rollback
    get_connection(using).savepoint_rollback(sid)
  File ""$VIRTUAL_ENV/lib/python3.5/site-packages/django/db/backends/base/base.py"", line 328, in savepoint_rollback
    self._savepoint_rollback(sid)
  File ""$VIRTUAL_ENV/lib/python3.5/site-packages/django/db/backends/base/base.py"", line 288, in _savepoint_rollback
    cursor.execute(self.ops.savepoint_rollback_sql(sid))
  File ""$VIRTUAL_ENV/lib/python3.5/site-packages/django/db/backends/utils.py"", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File ""$VIRTUAL_ENV/lib/python3.5/site-packages/django/db/backends/utils.py"", line 59, in execute
    self.db.validate_no_broken_transaction()
  File ""$VIRTUAL_ENV/lib/python3.5/site-packages/django/db/backends/base/base.py"", line 429, in validate_no_broken_transaction
    ""An error occurred in the current transaction. You can't ""
django.db.transaction.TransactionManagementError: An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block.
}}}
"	Bug	new	Database layer (models, ORM)	1.9	Normal			Tore Lundqvist	Accepted	0	0	0	0	0	0
