mirror of https://github.com/django/django.git
Refs #31051 -- Added test for loaddata/dumpdata with circular references without natural keys.
This commit is contained in:
parent
cf21fc9bf0
commit
481d8fc324
|
@ -0,0 +1,18 @@
|
|||
[
|
||||
{
|
||||
"model": "fixtures.circulara",
|
||||
"pk": 1,
|
||||
"fields": {
|
||||
"key": "x",
|
||||
"obj": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "fixtures.circularb",
|
||||
"pk": 1,
|
||||
"fields": {
|
||||
"key": "y",
|
||||
"obj": 1
|
||||
}
|
||||
}
|
||||
]
|
|
@ -134,3 +134,13 @@ class NaturalKeyThing(models.Model):
|
|||
|
||||
def __str__(self):
|
||||
return self.key
|
||||
|
||||
|
||||
class CircularA(models.Model):
|
||||
key = models.CharField(max_length=3, unique=True)
|
||||
obj = models.ForeignKey('CircularB', models.SET_NULL, null=True)
|
||||
|
||||
|
||||
class CircularB(models.Model):
|
||||
key = models.CharField(max_length=3, unique=True)
|
||||
obj = models.ForeignKey('CircularA', models.SET_NULL, null=True)
|
||||
|
|
|
@ -17,8 +17,8 @@ from django.db import IntegrityError, connection
|
|||
from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature
|
||||
|
||||
from .models import (
|
||||
Article, Category, NaturalKeyThing, PrimaryKeyUUIDModel, ProxySpy, Spy,
|
||||
Tag, Visa,
|
||||
Article, Category, CircularA, CircularB, NaturalKeyThing,
|
||||
PrimaryKeyUUIDModel, ProxySpy, Spy, Tag, Visa,
|
||||
)
|
||||
|
||||
|
||||
|
@ -804,3 +804,19 @@ class ForwardReferenceTests(TestCase):
|
|||
t1.other_things.order_by('key'),
|
||||
['<NaturalKeyThing: t2>', '<NaturalKeyThing: t3>']
|
||||
)
|
||||
|
||||
|
||||
class CircularReferenceTests(DumpDataAssertMixin, TestCase):
|
||||
def test_circular_reference(self):
|
||||
management.call_command('loaddata', 'circular_reference.json', verbosity=0)
|
||||
obj_a = CircularA.objects.get()
|
||||
obj_b = CircularB.objects.get()
|
||||
self.assertEqual(obj_a.obj, obj_b)
|
||||
self.assertEqual(obj_b.obj, obj_a)
|
||||
self._dumpdata_assert(
|
||||
['fixtures'],
|
||||
'[{"model": "fixtures.circulara", "pk": 1, '
|
||||
'"fields": {"key": "x", "obj": 1}}, '
|
||||
'{"model": "fixtures.circularb", "pk": 1, '
|
||||
'"fields": {"key": "y", "obj": 1}}]',
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue