Opened 13 years ago
Closed 13 years ago
#16397 closed Bug (fixed)
BaseCommand.execute() swallows ImportError, CommandError even when --traceback is used
Reported by: | 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)
Change History (7)
comment:1 by , 13 years ago
comment:2 by , 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 , 13 years ago
Has patch: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
by , 13 years ago
Attachment: | 16397.diff added |
---|
comment:4 by , 13 years ago
Needs tests: | set |
---|
comment:5 by , 13 years ago
Owner: | changed from | to
---|
Could you provide a snippet to help us reproduce this problem?