Opened 6 years ago

Closed 6 years ago

#20445 closed Bug (fixed)

BaseCommand --traceback should raise the original Exception

Reported by: jorgebastida Owned by: jorgebastida
Component: Core (Management commands) 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


When you are debugging long-running process that take hours to finish is really helpful to run them using ipython --pdb <script> so in case of failure, you'll get a ipdb trace just before the Exception was raised, so you can check what was wrong and fix it instead of adding an ipdb and re running the script.

As for the last weeks I've been writing some django command that takes hours to run I tried to run these scripts using ipython --pdb <command> but unfortunately I found that BaseCommand.run_from_argv was capturing any Exception raised by my command and printing the traceback to stderr if the --traceback option was present, or name and error if not.

In order to use ipython --pdb I need to override run_from_argv In my commands and basically don't try/except self.execute(*args, **options.__dict__) what is pretty hacky.

After talking with Russell Keith-Magee we found that, as python default behavior is to print the traceback into stderr}} and return an error status code when an Exception is raised and not captured, the solution would probably be to {{{raise the Exception if --traceback is present. The consequences are:

a) The existing behavior doesn't change.
b) We can call commands from interpreters that do fancy things when exceptions are raised.

I haven't found anything related in the "Better Error Message" wiki page:

Change History (6)

comment:1 Changed 6 years ago by jorgebastida

Status: newassigned

comment:2 Changed 6 years ago by Russell Keith-Magee

Triage Stage: UnreviewedAccepted

comment:3 Changed 6 years ago by jorgebastida

Pull request available here

comment:4 Changed 6 years ago by jorgebastida

Has patch: set

comment:5 Changed 6 years ago by Claude Paroz

Triage Stage: AcceptedReady for checkin

This makes sense.

comment:6 Changed 6 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: assignedclosed

In 888c86dcf30defe533451bcefc6e09a6e181389f:

Fixed #20445 -- Raised original exception after command error

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