Enhanced loaddata error message printed when no DB fixture is provided.

Fixes #7043 by fixing the last code path where a misleading 'No fixtures found.' error message was being shown.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17051 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Ramiro Morales 2011-10-29 14:47:45 +00:00
parent 69eadc7f15
commit 345be05622
2 changed files with 28 additions and 11 deletions

View File

@ -39,6 +39,12 @@ class Command(BaseCommand):
connection = connections[using]
self.style = no_style()
if not len(fixture_labels):
self.stderr.write(
self.style.ERROR("No database fixture specified. Please provide the path of at least one fixture in the command line.\n")
)
return
verbosity = int(options.get('verbosity'))
show_traceback = options.get('traceback')
@ -245,17 +251,13 @@ class Command(BaseCommand):
transaction.commit(using=using)
transaction.leave_transaction_management(using=using)
if fixture_object_count == 0:
if verbosity >= 1:
self.stdout.write("No fixtures found.\n")
else:
if verbosity >= 1:
if fixture_object_count == loaded_object_count:
self.stdout.write("Installed %d object(s) from %d fixture(s)\n" % (
loaded_object_count, fixture_count))
else:
self.stdout.write("Installed %d object(s) (of %d) from %d fixture(s)\n" % (
loaded_object_count, fixture_object_count, fixture_count))
if verbosity >= 1:
if fixture_object_count == loaded_object_count:
self.stdout.write("Installed %d object(s) from %d fixture(s)\n" % (
loaded_object_count, fixture_count))
else:
self.stdout.write("Installed %d object(s) (of %d) from %d fixture(s)\n" % (
loaded_object_count, fixture_object_count, fixture_count))
# Close the DB connection. This is required as a workaround for an
# edge case in MySQL: if the same connection is used to

View File

@ -390,6 +390,21 @@ class TestFixtures(TestCase):
stderr.getvalue().startswith('Problem installing fixture')
)
def test_loaddata_no_fixture_specified(self):
"""
Regression for #7043 - Error is quickly reported when no fixtures is provided in the command line.
"""
stderr = StringIO()
management.call_command(
'loaddata',
verbosity=0,
commit=False,
stderr=stderr,
)
self.assertEqual(
stderr.getvalue(), 'No database fixture specified. Please provide the path of at least one fixture in the command line.\n'
)
class NaturalKeyFixtureTests(TestCase):