Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 345be056227325817ea0f419556ce877c49c9d5b 1 parent 69eadc7
@ramiro ramiro authored
View
24 django/core/management/commands/loaddata.py
@@ -39,6 +39,12 @@ def handle(self, *fixture_labels, **options):
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 @@ def read(self):
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
15 tests/regressiontests/fixtures_regress/tests.py
@@ -390,6 +390,21 @@ def test_loaddata_raises_error_when_fixture_has_invalid_foreign_key(self):
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):
Please sign in to comment.
Something went wrong with that request. Please try again.