mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #31051 -- Allowed dumpdata to handle circular references in natural keys.
Since #26291 forward references in natural keys are properly handled by loaddata, so sorting depenencies in dumpdata doesn't need to break on cycles. This patch allows circular references in natural keys by breaking sort_depenencies() on loops.
This commit is contained in:
committed by
Mariusz Felisiak
parent
590957a0eb
commit
4f216e4f8e
20
tests/fixtures/tests.py
vendored
20
tests/fixtures/tests.py
vendored
@@ -880,3 +880,23 @@ class CircularReferenceTests(DumpDataAssertMixin, TestCase):
|
||||
'{"model": "fixtures.circularb", "pk": 1, '
|
||||
'"fields": {"key": "y", "obj": 1}}]',
|
||||
)
|
||||
|
||||
def test_circular_reference_natural_key(self):
|
||||
management.call_command(
|
||||
'loaddata',
|
||||
'circular_reference_natural_key.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", '
|
||||
'"fields": {"key": "x", "obj": ["y"]}}, '
|
||||
'{"model": "fixtures.circularb", '
|
||||
'"fields": {"key": "y", "obj": ["x"]}}]',
|
||||
natural_primary_keys=True,
|
||||
natural_foreign_keys=True,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user