Opened 13 years ago

Closed 12 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

Description

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 13 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 by Aymeric Augustin, 13 years ago

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

comment:2 by anonymous, 13 years ago

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

from django.core.management.base 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')

...in 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 by Aymeric Augustin, 13 years ago

Has patch: set
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

by Aymeric Augustin, 13 years ago

Attachment: 16397.diff added

comment:4 by Adam Nelson, 13 years ago

Needs tests: set

comment:5 by Aymeric Augustin, 12 years ago

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 by Aymeric Augustin, 12 years ago

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