#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:

Attachments (0)

Change History (6)

comment:1 Changed 14 months ago by jorgebastida

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Status changed from new to assigned

comment:2 Changed 14 months ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 14 months ago by jorgebastida

Pull request available here

comment:4 Changed 14 months ago by jorgebastida

  • Has patch set

comment:5 Changed 14 months ago by claudep

  • Triage Stage changed from Accepted to Ready for checkin

This makes sense.

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

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

In 888c86dcf30defe533451bcefc6e09a6e181389f:

Fixed #20445 -- Raised original exception after command error

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.