summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
Diffstat (limited to 'django')
-rw-r--r--django/core/management/base.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/django/core/management/base.py b/django/core/management/base.py
index 895753ea12..7b9001ed14 100644
--- a/django/core/management/base.py
+++ b/django/core/management/base.py
@@ -221,9 +221,12 @@ class BaseCommand(object):
try:
self.execute(*args, **options.__dict__)
except Exception as e:
+ # self.stderr is not guaranteed to be set here
+ stderr = getattr(self, 'stderr', OutputWrapper(sys.stderr, self.style.ERROR))
if options.traceback:
- self.stderr.write(traceback.format_exc())
- self.stderr.write('%s: %s' % (e.__class__.__name__, e))
+ stderr.write(traceback.format_exc())
+ else:
+ stderr.write('%s: %s' % (e.__class__.__name__, e))
sys.exit(1)
def execute(self, *args, **options):