diff options
| author | Ramiro Morales <cramm0@gmail.com> | 2011-10-29 14:47:45 +0000 |
|---|---|---|
| committer | Ramiro Morales <cramm0@gmail.com> | 2011-10-29 14:47:45 +0000 |
| commit | 345be056227325817ea0f419556ce877c49c9d5b (patch) | |
| tree | 4494dec7269c39c1f08555f0b64021ffed652b1b | |
| parent | 69eadc7f15c6bd2b3631037f500bc6c77b381a38 (diff) | |
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
| -rw-r--r-- | django/core/management/commands/loaddata.py | 24 | ||||
| -rw-r--r-- | tests/regressiontests/fixtures_regress/tests.py | 15 |
2 files changed, 28 insertions, 11 deletions
diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py index 356e2d08bd..4492e5c6cb 100644 --- a/django/core/management/commands/loaddata.py +++ b/django/core/management/commands/loaddata.py @@ -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 diff --git a/tests/regressiontests/fixtures_regress/tests.py b/tests/regressiontests/fixtures_regress/tests.py index 5c448e67b1..26e436b3c5 100644 --- a/tests/regressiontests/fixtures_regress/tests.py +++ b/tests/regressiontests/fixtures_regress/tests.py @@ -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): |
