Django

Code

Ticket #7241 (new)

Opened 2 months ago

Last modified 5 days ago

Transaction management does not catch all exceptions

Reported by: jim <jim-django@dsdd.org> Assigned to: nobody
Milestone: Component: Database wrapper
Version: SVN Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Expectation: When a view is decorated with commit_on_success, any exception raised in that view should cause a rollback of the current transaction. If no exception occurs, the transaction should be committed.

Experience: There are many exceptions that are not caught by commit_on_success. When one of these is raised, neither a rollback nor a commit is done. This causes a TransactionManagementError? in leave_transaction_management().

The only exceptions caught are subclasses of Python's built in Exception class. Since Python allows any object to be raised as an exception, this leaves an unprotected path in the code.

For example (untested, just an illustration):

@commit_on_success
def my_view(request):
   raise "simple debug exception"

The object being raised will not match commit_on_success's handler, and the error condition is triggered.

Note: Yes, string exceptions are deprecated. But they are still possible, and must be guarded against.

Simple patch attached.

Attachments

catchmore.patch (437 bytes) - added by jim <jim-django@dsdd.org> on 05/14/08 15:40:56.
simple patch

Change History

05/14/08 15:40:56 changed by jim <jim-django@dsdd.org>

  • attachment catchmore.patch added.

simple patch

05/15/08 00:56:09 changed by Bernd Schlapsi

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

I think #6623 is related to this issue

07/01/08 09:17:37 changed by jim <jim-django@dsdd.org>

Notice that this is not the classic misguided "naked except", as it re-raises immediately after the rollback.


Add/Change #7241 (Transaction management does not catch all exceptions)




Change Properties
Action