Opened 8 years ago

Closed 4 years ago

#6928 closed Uncategorized (fixed)

commit_on_success: Handle KeyboardInterrupt

Reported by: guettli Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


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/", line 148, in <module>
  File "/localhome/modw/listen/bin/", line 68, in main
    index(file, ignore_mtime=ignore_mtime)
  File "/localhome/modw/listen/bin/", line 78, in index
    index_file(file, ignore_mtime=ignore_mtime)
  File "/localhome/modw/modwork_esg/django/db/", line 204, in _commit_on_success
  File "/localhome/modw/modwork_esg/django/db/", 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:

Attachments (1)

6928.diff (471 bytes) - added by guettli 8 years ago.
Handle KeyboardInterrupt.

Download all attachments as: .zip

Change History (9)

Changed 8 years ago by guettli

Handle KeyboardInterrupt.

comment:1 Changed 7 years ago by telenieko

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Is there any reason to check KeyboardInterrupt instead of BaseException?

comment:2 Changed 7 years ago 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.

comment:3 Changed 7 years ago by telenieko

  • Triage Stage changed from Accepted to Ready for checkin

Thanks for the explanation ;)

comment:4 Changed 7 years ago 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).

comment:5 Changed 7 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:6 Changed 7 years ago by guettli

  • Cc hv@… removed

comment:7 Changed 4 years ago by nmk

  • Easy pickings unset
  • Resolution fixed deleted
  • Severity set to Normal
  • Status changed from closed to reopened
  • Type set to Uncategorized
  • UI/UX unset

after [14288] transaction.commit_on_success does not handle KeyboardInterrupt.

Problem in django.db.transaction.Transaction.__exit__ and default exiting function.

    def __exit__(self, exc_type, exc_value, traceback):
        self.exiting(exc_value, self.using)

exc_value is None after KeybordInterrupt has been throwed, only exc_type and traceback has value.
But if raise KeybordInterrupt manualy from code it's work ok.

Possible solution: use exc_type and exc_value in exiting function

I use python 2.6.6

comment:8 Changed 4 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from reopened to closed

The issue in this ticket was closed long ago. The new comment refers to a new issue, so I have created ticket #16682 for that. Closing this again.

Note: See TracTickets for help on using tickets.
Back to Top