Fixed a bug introduced by [9527] -- empty/invalid fixtures were no longer being reported.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9528 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jacob Kaplan-Moss 2008-11-24 21:13:33 +00:00
parent 089ab18c02
commit f4879af2df
1 changed files with 14 additions and 1 deletions

View File

@ -132,15 +132,17 @@ class Command(BaseCommand):
return
else:
fixture_count += 1
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_in_fixture += 1
models.add(obj.object.__class__)
obj.save()
object_count += objects_in_fixture
label_found = True
except (SystemExit, KeyboardInterrupt):
raise
@ -158,6 +160,17 @@ 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 Exception, e:
if verbosity > 1:
print "No %s fixture '%s' in %s." % \