diff options
| author | Eli Bendersky <eliben@gmail.com> | 2014-02-11 06:59:57 -0800 |
|---|---|---|
| committer | Baptiste Mispelon <bmispelon@gmail.com> | 2014-02-12 15:34:26 +0100 |
| commit | 73f51e411372ba3e74ccf5a2c2be88927ac2c6dd (patch) | |
| tree | 74a5787a2e908b7d203a937a3994b658fc33daaa | |
| parent | e0381cdf2e7f677c5b29f2e3351993e92915569a (diff) | |
Fixed #22025 -- Listing app followed by app.Model in dumpdata command
When invoked as follows:
$ python manage.py dumpdata blogapp blogapp.Tag
Django would throw a TypeError. This commit fixes the problem and provides
a test.
| -rw-r--r-- | django/core/management/commands/dumpdata.py | 9 | ||||
| -rw-r--r-- | tests/fixtures/tests.py | 4 |
2 files changed, 11 insertions, 2 deletions
diff --git a/django/core/management/commands/dumpdata.py b/django/core/management/commands/dumpdata.py index eb5d9ffd50..8150219cbd 100644 --- a/django/core/management/commands/dumpdata.py +++ b/django/core/management/commands/dumpdata.py @@ -102,8 +102,13 @@ class Command(BaseCommand): raise CommandError("Unknown model: %s.%s" % (app_label, model_label)) app_list_value = app_list.setdefault(app_config, []) - if model not in app_list_value: - app_list_value.append(model) + + # We may have previously seen a "all-models" request for + # this app (no model qualifier was given). In this case + # there is no need adding specific models to the list. + if app_list_value is not None: + if model not in app_list_value: + app_list_value.append(model) except ValueError: if primary_keys: raise CommandError("You can only use --pks option with one model") diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py index 9a8a0cc8ca..a964ae79d7 100644 --- a/tests/fixtures/tests.py +++ b/tests/fixtures/tests.py @@ -93,6 +93,10 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): # Specify a dump that specifies Article both explicitly and implicitly self._dumpdata_assert(['fixtures.Article', 'fixtures'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}, {"pk": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]') + # Specify a dump that specifies Article both explicitly and implicitly, + # but lists the app first (#22025). + self._dumpdata_assert(['fixtures', 'fixtures.Article'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}, {"pk": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]') + # Same again, but specify in the reverse order self._dumpdata_assert(['fixtures'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}, {"pk": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]') |
