Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #16397 -- Respected the --traceback flag in BaseCommand. This s…

…hould make import loops easier to debug. Refs #11667, #17369.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17197 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 694bc0f22bdb30a472de6fec05a44adf5c0f1f2c 1 parent affca13
Aymeric Augustin aaugustin authored
15 django/core/management/base.py
View
@@ -7,6 +7,7 @@
import os
import sys
from optparse import make_option, OptionParser
+import traceback
import django
from django.core.exceptions import ImproperlyConfigured
@@ -197,8 +198,9 @@ def execute(self, *args, **options):
``self.requires_model_validation``). If the command raises a
``CommandError``, intercept it and print it sensibly to
stderr.
-
"""
+ show_traceback = options.get('traceback', False)
+
# Switch to English, because django-admin.py creates database content
# like permissions, and those shouldn't contain any translations.
# But only do this if we can assume we have a working settings file,
@@ -212,8 +214,12 @@ def execute(self, *args, **options):
except ImportError, e:
# If settings should be available, but aren't,
# raise the error and quit.
- sys.stderr.write(smart_str(self.style.ERROR('Error: %s\n' % e)))
+ if show_traceback:
+ traceback.print_exc()
+ else:
+ sys.stderr.write(smart_str(self.style.ERROR('Error: %s\n' % e)))
sys.exit(1)
+
try:
self.stdout = options.get('stdout', sys.stdout)
self.stderr = options.get('stderr', sys.stderr)
@@ -232,7 +238,10 @@ def execute(self, *args, **options):
if self.output_transaction:
self.stdout.write('\n' + self.style.SQL_KEYWORD("COMMIT;") + '\n')
except CommandError, e:
- self.stderr.write(smart_str(self.style.ERROR('Error: %s\n' % e)))
+ if show_traceback:
+ traceback.print_exc()
+ else:
+ self.stderr.write(smart_str(self.style.ERROR('Error: %s\n' % e)))
sys.exit(1)
if saved_lang is not None:
translation.activate(saved_lang)
2  django/core/management/commands/loaddata.py
View
@@ -7,6 +7,7 @@
import gzip
import zipfile
from optparse import make_option
+import traceback
from django.conf import settings
from django.core import serializers
@@ -211,7 +212,6 @@ def read(self):
except (SystemExit, KeyboardInterrupt):
raise
except Exception:
- import traceback
fixture.close()
if commit:
transaction.rollback(using=using)
2  django/core/management/commands/syncdb.py
View
@@ -1,5 +1,6 @@
from optparse import make_option
import sys
+import traceback
from django.conf import settings
from django.core.management.base import NoArgsCommand
@@ -129,7 +130,6 @@ def model_installed(model):
sys.stderr.write("Failed to install custom SQL for %s.%s model: %s\n" % \
(app_name, model._meta.object_name, e))
if show_traceback:
- import traceback
traceback.print_exc()
transaction.rollback_unless_managed(using=db)
else:
Please sign in to comment.
Something went wrong with that request. Please try again.