Django

Code

Ticket #6928 (closed: fixed)

Opened 6 months ago

Last modified 1 month ago

commit_on_success: Handle KeyboardInterrupt

Reported by: guettli Assigned to: nobody
Milestone: Component: Database layer (models, ORM)
Version: SVN Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Since Python 2.5 KeyboardInterrupt? does not inherit from Exception, but from BaseException?. If there is a bug in a method which uses commit_on_success and you hit ctrl-c on the shell, you don't see the real traceback, but only this:

Traceback (most recent call last):
  File "/localhome/modw/listen/bin/index.py", line 148, in <module>
    main()
  File "/localhome/modw/listen/bin/index.py", line 68, in main
    index(file, ignore_mtime=ignore_mtime)
  File "/localhome/modw/listen/bin/index.py", line 78, in index
    index_file(file, ignore_mtime=ignore_mtime)
  File "/localhome/modw/modwork_esg/django/db/transaction.py", line 204, in _commit_on_success
    leave_transaction_management()
  File "/localhome/modw/modwork_esg/django/db/transaction.py", line 70, in leave_transaction_management
    raise TransactionManagementError("Transaction managed block ended with pending COMMIT/ROLLBACK")
django.db.transaction.TransactionManagementError: Transaction managed block ended with pending COMMIT/ROLLBACK

This small patch handles KeyboardInterrupt? in commit_on_success() better.

Python Docu for KeyboardInterrupt?: http://docs.python.org/lib/module-exceptions.html#l2h-111

Attachments

6928.diff (471 bytes) - added by guettli on 03/31/08 05:10:06.
Handle KeyboardInterrupt?.

Change History

03/31/08 05:10:06 changed by guettli

  • attachment 6928.diff added.

06/14/08 07:01:34 changed by telenieko

  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • needs_docs changed.

Is there any reason to check KeyboardInterrupt? instead of BaseException??

06/16/08 01:25:46 changed by guettli

I didn't use BaseException since it was introduced in Python 2.5. Django tries to support Python 2.3.

Thank you for looking at this patch.

06/16/08 02:47:57 changed by telenieko

  • stage changed from Accepted to Ready for checkin.

Thanks for the explanation ;)

06/30/08 06:53:02 changed by mtredinnick

I'm going to through SystemExit in there as well, for all the same reasons, I think. No need to treat that specially in that particular case (although it may well fail anyway for other reasons).

06/30/08 06:56:53 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(In [7802]) Fixed #6928 -- Added a little more robustness to transaction rollbacks for Python 2.5. Patch from guettli.

09/04/08 10:02:56 changed by guettli

  • cc deleted.

Add/Change #6928 (commit_on_success: Handle KeyboardInterrupt)




Change Properties
Action