summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorJorge Bastida <me@jorgebastida.com>2013-05-18 18:04:45 +0200
committerClaude Paroz <claude@2xlibre.net>2013-05-20 18:59:37 +0200
commit888c86dcf30defe533451bcefc6e09a6e181389f (patch)
treed1e57aeb3bfe77f40b7f494f1ecdaa7e80ffe7db /django
parent4280217f31fc634d320b0cf30bcb6d582b19d784 (diff)
Fixed #20445 -- Raised original exception after command error
Diffstat (limited to 'django')
-rw-r--r--django/core/management/base.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/django/core/management/base.py b/django/core/management/base.py
index ba6ad8f4c0..af040288d0 100644
--- a/django/core/management/base.py
+++ b/django/core/management/base.py
@@ -7,7 +7,6 @@ import os
import sys
from optparse import make_option, OptionParser
-import traceback
import django
from django.core.exceptions import ImproperlyConfigured
@@ -171,7 +170,7 @@ class BaseCommand(object):
make_option('--pythonpath',
help='A directory to add to the Python path, e.g. "/home/djangoprojects/myproject".'),
make_option('--traceback', action='store_true',
- help='Print traceback on exception'),
+ help='Raise on exception'),
)
help = ''
args = ''
@@ -231,7 +230,8 @@ class BaseCommand(object):
Set up any environment changes requested (e.g., Python path
and Django settings), then run this command. If the
command raises a ``CommandError``, intercept it and print it sensibly
- to stderr.
+ to stderr. If the ``--traceback`` option is present or the raised
+ ``Exception`` is not ``CommandError``, raise it.
"""
parser = self.create_parser(argv[0], argv[1])
options, args = parser.parse_args(argv[2:])
@@ -239,12 +239,12 @@ class BaseCommand(object):
try:
self.execute(*args, **options.__dict__)
except Exception as e:
+ if options.traceback or not isinstance(e, CommandError):
+ raise
+
# self.stderr is not guaranteed to be set here
stderr = getattr(self, 'stderr', OutputWrapper(sys.stderr, self.style.ERROR))
- if options.traceback or not isinstance(e, CommandError):
- stderr.write(traceback.format_exc())
- else:
- stderr.write('%s: %s' % (e.__class__.__name__, e))
+ stderr.write('%s: %s' % (e.__class__.__name__, e))
sys.exit(1)
def execute(self, *args, **options):