Opened 9 years ago

Closed 8 years ago

#16397 closed Bug (fixed)

BaseCommand.execute() swallows ImportError, CommandError even when --traceback is used

Reported by: charles@… Owned by: Aymeric Augustin
Component: Core (Management commands) Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no


Any ImportError or CommandError happening during BaseCommand.execute() is emitted as a single-line exception, even if --traceback is used. This can make exceptions caused by import loops difficult to debug.

--traceback should be honored, emitting full stack traces.

Attachments (1)

16397.diff (1.7 KB) - added by Aymeric Augustin 9 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 9 years ago by Aymeric Augustin

Could you provide a snippet to help us reproduce this problem?

comment:2 Changed 9 years ago by anonymous

The easy-to-reproduce case is raising a CommandError from anywhere in execution:

from import BaseCommand, CommandError

class Command(BaseCommand):
    """Trigger an ImportError with no stack trace even when --traceback is used"""

    help = 'Demonstrate #16397'

    def handle(self, *arguments, **options):
        raise CommandError('foo') this case, running the command, even with --traceback, simply results in a single line of output: Error: foo.

However, this isn't much of a bug -- CommandErrors don't tend to happen anywhere but in management commands, and handling them in a user-friendly way tends to be desired behavior (though I think it might be fair to break that rule when --traceback is in use).

The much more interesting case is triggering an ImportError during translation.activate() -- this is what was biting me in practice. However, reproducing it (with the various bugs in my codebase which lead to it happening in practice fixed) appears to be nontrivial. I'll revisit this later.

comment:3 Changed 9 years ago by Aymeric Augustin

Has patch: set
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

Changed 9 years ago by Aymeric Augustin

Attachment: 16397.diff added

comment:4 Changed 9 years ago by Adam Nelson

Needs tests: set

comment:5 Changed 8 years ago by Aymeric Augustin

Owner: changed from nobody to Aymeric Augustin

#11667 was closed as a duplicate, check the discussions and patches over there before committing a fix for this ticket.

#17369 was also closed as a duplicate.

comment:6 Changed 8 years ago by Aymeric Augustin

Resolution: fixed
Status: newclosed

In [17197]:

Fixed #16397 -- Respected the --traceback flag in BaseCommand. This should make import loops easier to debug. Refs #11667, #17369.

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