summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-12-17 11:09:32 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-12-17 11:09:32 +0000
commitfbf49dfceed2958da3d6edcbe6119284bf95894e (patch)
tree965cc187600e0e6e7a044695aa860859d4852099
parent9229c34163982320db6f9ee4473964699893d79f (diff)
Fixed #4431 -- Added a --traceback option for dumpdata and loaddata (which
shows how it can be used for other commands as well). Thanks, dakrauth. git-svn-id: http://code.djangoproject.com/svn/django/trunk@6936 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/core/management/base.py2
-rw-r--r--django/core/management/commands/dumpdata.py3
-rw-r--r--django/core/management/commands/loaddata.py7
3 files changed, 10 insertions, 2 deletions
diff --git a/django/core/management/base.py b/django/core/management/base.py
index 31c2849075..7b8a3e987f 100644
--- a/django/core/management/base.py
+++ b/django/core/management/base.py
@@ -27,6 +27,8 @@ class BaseCommand(object):
help='The Python path to a settings module, e.g. "myproject.settings.main". If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be used.'),
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 = ''
args = ''
diff --git a/django/core/management/commands/dumpdata.py b/django/core/management/commands/dumpdata.py
index 090053aaf9..01b44a8282 100644
--- a/django/core/management/commands/dumpdata.py
+++ b/django/core/management/commands/dumpdata.py
@@ -19,6 +19,7 @@ class Command(BaseCommand):
format = options.get('format', 'json')
indent = options.get('indent', None)
+ show_traceback = options.get('traceback', False)
if len(app_labels) == 0:
app_list = get_apps()
@@ -42,4 +43,6 @@ class Command(BaseCommand):
try:
return serializers.serialize(format, objects, indent=indent)
except Exception, e:
+ if show_traceback:
+ raise
raise CommandError("Unable to serialize database: %s" % e)
diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py
index e22b78d517..fb0325906d 100644
--- a/django/core/management/commands/loaddata.py
+++ b/django/core/management/commands/loaddata.py
@@ -27,6 +27,7 @@ class Command(BaseCommand):
self.style = no_style()
verbosity = int(options.get('verbosity', 1))
+ show_traceback = options.get('traceback', False)
# Keep a count of the installed objects and fixtures
count = [0, 0]
@@ -98,11 +99,13 @@ class Command(BaseCommand):
label_found = True
except Exception, e:
fixture.close()
+ transaction.rollback()
+ transaction.leave_transaction_management()
+ if show_traceback:
+ raise
sys.stderr.write(
self.style.ERROR("Problem installing fixture '%s': %s\n" %
(full_path, str(e))))
- transaction.rollback()
- transaction.leave_transaction_management()
return
fixture.close()
except: