From 73f51e411372ba3e74ccf5a2c2be88927ac2c6dd Mon Sep 17 00:00:00 2001
From: Eli Bendersky <eliben@gmail.com>
Date: Tue, 11 Feb 2014 06:59:57 -0800
Subject: [PATCH] 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.
---
 django/core/management/commands/dumpdata.py | 9 +++++++--
 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": []}}]')