#26340: Cannot rollback to a savepoint explicitly after an IntegrityError when autocommit is disabled -------------------------------------+------------------------------------- Reporter: aaugustin | Owner: nobody Type: Bug | Status: new Component: Database | Version: 1.9 layer (models, ORM) | Severity: Normal | Keywords: Triage Stage: | Has patch: 0 Unreviewed | Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 0 UI/UX: 0 | -------------------------------------+------------------------------------- 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. }}} -- Ticket URL: <https://code.djangoproject.com/ticket/26340> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/052.d44c08391ccbadf8fdc7b81f9f2af5ff%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.