Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 Morales authored October 29, 2011
24  django/core/management/commands/loaddata.py
@@ -39,6 +39,12 @@ def handle(self, *fixture_labels, **options):
39 39
         connection = connections[using]
40 40
         self.style = no_style()
41 41
 
  42
+        if not len(fixture_labels):
  43
+            self.stderr.write(
  44
+                self.style.ERROR("No database fixture specified. Please provide the path of at least one fixture in the command line.\n")
  45
+            )
  46
+            return
  47
+
42 48
         verbosity = int(options.get('verbosity'))
43 49
         show_traceback = options.get('traceback')
44 50
 
@@ -245,17 +251,13 @@ def read(self):
245 251
             transaction.commit(using=using)
246 252
             transaction.leave_transaction_management(using=using)
247 253
 
248  
-        if fixture_object_count == 0:
249  
-            if verbosity >= 1:
250  
-                self.stdout.write("No fixtures found.\n")
251  
-        else:
252  
-            if verbosity >= 1:
253  
-                if fixture_object_count == loaded_object_count:
254  
-                    self.stdout.write("Installed %d object(s) from %d fixture(s)\n" % (
255  
-                        loaded_object_count, fixture_count))
256  
-                else:
257  
-                    self.stdout.write("Installed %d object(s) (of %d) from %d fixture(s)\n" % (
258  
-                        loaded_object_count, fixture_object_count, fixture_count))
  254
+        if verbosity >= 1:
  255
+            if fixture_object_count == loaded_object_count:
  256
+                self.stdout.write("Installed %d object(s) from %d fixture(s)\n" % (
  257
+                    loaded_object_count, fixture_count))
  258
+            else:
  259
+                self.stdout.write("Installed %d object(s) (of %d) from %d fixture(s)\n" % (
  260
+                    loaded_object_count, fixture_object_count, fixture_count))
259 261
 
260 262
         # Close the DB connection. This is required as a workaround for an
261 263
         # edge case in MySQL: if the same connection is used to
15  tests/regressiontests/fixtures_regress/tests.py
@@ -390,6 +390,21 @@ def test_loaddata_raises_error_when_fixture_has_invalid_foreign_key(self):
390 390
             stderr.getvalue().startswith('Problem installing fixture')
391 391
         )
392 392
 
  393
+    def test_loaddata_no_fixture_specified(self):
  394
+        """
  395
+        Regression for #7043 - Error is quickly reported when no fixtures is provided in the command line.
  396
+        """
  397
+        stderr = StringIO()
  398
+        management.call_command(
  399
+            'loaddata',
  400
+            verbosity=0,
  401
+            commit=False,
  402
+            stderr=stderr,
  403
+        )
  404
+        self.assertEqual(
  405
+            stderr.getvalue(), 'No database fixture specified. Please provide the path of at least one fixture in the command line.\n'
  406
+        )
  407
+
393 408
 
394 409
 class NaturalKeyFixtureTests(TestCase):
395 410
 

0 notes on commit 345be05

Please sign in to comment.
Something went wrong with that request. Please try again.