summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2008-11-06 11:19:13 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2008-11-06 11:19:13 +0000
commitb2d2c570b7a8936f60645175c48bfae5eb2481fa (patch)
tree10e983cd1ebcbfa549c7de0dbabae3e679644667 /django
parentfb8a7702a022e5d85398838ab1a0a797519ac9cc (diff)
Fixed #9011 -- Corrected handling of fixture files that contain errors to correctly report the broken fixture name. Thanks to jlrivitti@gmail.com for the report and initial patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9357 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/core/management/commands/loaddata.py28
1 files changed, 13 insertions, 15 deletions
diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py
index 7467f983e8..d073fea812 100644
--- a/django/core/management/commands/loaddata.py
+++ b/django/core/management/commands/loaddata.py
@@ -35,7 +35,6 @@ class Command(BaseCommand):
# Keep a count of the installed objects and fixtures
fixture_count = 0
object_count = 0
- objects_per_fixture = []
models = set()
humanize = lambda dirname: dirname and "'%s'" % dirname or 'absolute path'
@@ -103,17 +102,17 @@ class Command(BaseCommand):
return
else:
fixture_count += 1
- objects_per_fixture.append(0)
+ objects_in_fixture = 0
if verbosity > 0:
print "Installing %s fixture '%s' from %s." % \
(format, fixture_name, humanize(fixture_dir))
try:
objects = serializers.deserialize(format, fixture)
for obj in objects:
- object_count += 1
- objects_per_fixture[-1] += 1
+ objects_in_fixture += 1
models.add(obj.object.__class__)
obj.save()
+ object_count += objects_in_fixture
label_found = True
except (SystemExit, KeyboardInterrupt):
raise
@@ -131,22 +130,21 @@ class Command(BaseCommand):
(full_path, traceback.format_exc())))
return
fixture.close()
+
+ # If the fixture we loaded contains 0 objects, assume that an
+ # error was encountered during fixture loading.
+ if objects_in_fixture == 0:
+ sys.stderr.write(
+ self.style.ERROR("No fixture data found for '%s'. (File format may be invalid.)" %
+ (fixture_name)))
+ transaction.rollback()
+ transaction.leave_transaction_management()
+ return
except:
if verbosity > 1:
print "No %s fixture '%s' in %s." % \
(format, fixture_name, humanize(fixture_dir))
-
- # If any of the fixtures we loaded contain 0 objects, assume that an
- # error was encountered during fixture loading.
- if 0 in objects_per_fixture:
- sys.stderr.write(
- self.style.ERROR("No fixture data found for '%s'. (File format may be invalid.)" %
- (fixture_name)))
- transaction.rollback()
- transaction.leave_transaction_management()
- return
-
# If we found even one object in a fixture, we need to reset the
# database sequences.
if object_count > 0: