Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #16317 -- Fixed dumpdata for self-referencing models and natura…

…l keys

Thanks aldaran for the patch.
  • Loading branch information...
commit 4b722b31e1778310ba0c1ed96fdacf99aa203dd2 1 parent 19a810b
Claude Paroz authored June 24, 2012
4  django/core/management/commands/dumpdata.py
@@ -150,11 +150,11 @@ def sort_dependencies(app_list):
150 150
             for field in model._meta.fields:
151 151
                 if hasattr(field.rel, 'to'):
152 152
                     rel_model = field.rel.to
153  
-                    if hasattr(rel_model, 'natural_key'):
  153
+                    if hasattr(rel_model, 'natural_key') and rel_model != model:
154 154
                         deps.append(rel_model)
155 155
             for field in model._meta.many_to_many:
156 156
                 rel_model = field.rel.to
157  
-                if hasattr(rel_model, 'natural_key'):
  157
+                if hasattr(rel_model, 'natural_key') and rel_model != model:
158 158
                     deps.append(rel_model)
159 159
             model_dependencies.append((model, deps))
160 160
 
4  tests/regressiontests/fixtures_regress/fixtures/forward_ref_lookup.json
@@ -10,6 +10,7 @@
10 10
         "pk": "2",
11 11
         "model": "fixtures_regress.store",
12 12
         "fields": {
  13
+            "main": null,
13 14
             "name": "Amazon"
14 15
         }
15 16
     },
@@ -17,6 +18,7 @@
17 18
         "pk": "3",
18 19
         "model": "fixtures_regress.store",
19 20
         "fields": {
  21
+            "main": null,
20 22
             "name": "Borders"
21 23
         }
22 24
     },
@@ -29,4 +31,4 @@
29 31
             "stores": [["Amazon"], ["Borders"]]
30 32
         }
31 33
     }
32  
-]
  34
+]
1  tests/regressiontests/fixtures_regress/models.py
@@ -91,6 +91,7 @@ def get_by_natural_key(self, key):
91 91
 class Store(models.Model):
92 92
     objects = TestManager()
93 93
     name = models.CharField(max_length=255)
  94
+    main = models.ForeignKey('self', null=True)
94 95
 
95 96
     class Meta:
96 97
         ordering = ('name',)
2  tests/regressiontests/fixtures_regress/tests.py
@@ -478,7 +478,7 @@ def test_nk_on_serialize(self):
478 478
         )
479 479
         self.assertEqual(
480 480
             stdout.getvalue(),
481  
-            """[{"pk": 2, "model": "fixtures_regress.store", "fields": {"name": "Amazon"}}, {"pk": 3, "model": "fixtures_regress.store", "fields": {"name": "Borders"}}, {"pk": 4, "model": "fixtures_regress.person", "fields": {"name": "Neal Stephenson"}}, {"pk": 1, "model": "fixtures_regress.book", "fields": {"stores": [["Amazon"], ["Borders"]], "name": "Cryptonomicon", "author": ["Neal Stephenson"]}}]"""
  481
+            """[{"pk": 2, "model": "fixtures_regress.store", "fields": {"main": null, "name": "Amazon"}}, {"pk": 3, "model": "fixtures_regress.store", "fields": {"main": null, "name": "Borders"}}, {"pk": 4, "model": "fixtures_regress.person", "fields": {"name": "Neal Stephenson"}}, {"pk": 1, "model": "fixtures_regress.book", "fields": {"stores": [["Amazon"], ["Borders"]], "name": "Cryptonomicon", "author": ["Neal Stephenson"]}}]"""
482 482
         )
483 483
 
484 484
     def test_dependency_sorting(self):

0 notes on commit 4b722b3

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