mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #14226 -- Dependency calculation for complex M2M relations.
`sort_dependencies` incorrectly interpreted 'complex' M2M relations (with explicit through models) as dependencies for a model. This caused circular complex M2M relations to be unserializable by dumpdata. Thanks to aneil for the report and outofculture for initial tests.
This commit is contained in:
parent
63df886df7
commit
a75324c654
3 changed files with 227 additions and 6 deletions
|
@ -235,3 +235,97 @@ class ExternalDependency(models.Model):
|
|||
# Model for regression test of #11101
|
||||
class Thingy(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class BaseNKModel(models.Model):
|
||||
"""
|
||||
Base model with a natural_key and a manager with `get_by_natural_key`
|
||||
"""
|
||||
data = models.CharField(max_length=20, unique=True)
|
||||
objects = NKManager()
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def __str__(self):
|
||||
return self.data
|
||||
|
||||
def natural_key(self):
|
||||
return (self.data,)
|
||||
|
||||
|
||||
class M2MSimpleA(BaseNKModel):
|
||||
b_set = models.ManyToManyField("M2MSimpleB")
|
||||
|
||||
|
||||
class M2MSimpleB(BaseNKModel):
|
||||
pass
|
||||
|
||||
|
||||
class M2MSimpleCircularA(BaseNKModel):
|
||||
b_set = models.ManyToManyField("M2MSimpleCircularB")
|
||||
|
||||
|
||||
class M2MSimpleCircularB(BaseNKModel):
|
||||
a_set = models.ManyToManyField("M2MSimpleCircularA")
|
||||
|
||||
|
||||
class M2MComplexA(BaseNKModel):
|
||||
b_set = models.ManyToManyField("M2MComplexB", through="M2MThroughAB")
|
||||
|
||||
|
||||
class M2MComplexB(BaseNKModel):
|
||||
pass
|
||||
|
||||
|
||||
class M2MThroughAB(BaseNKModel):
|
||||
a = models.ForeignKey(M2MComplexA)
|
||||
b = models.ForeignKey(M2MComplexB)
|
||||
|
||||
|
||||
class M2MComplexCircular1A(BaseNKModel):
|
||||
b_set = models.ManyToManyField("M2MComplexCircular1B",
|
||||
through="M2MCircular1ThroughAB")
|
||||
|
||||
|
||||
class M2MComplexCircular1B(BaseNKModel):
|
||||
c_set = models.ManyToManyField("M2MComplexCircular1C",
|
||||
through="M2MCircular1ThroughBC")
|
||||
|
||||
|
||||
class M2MComplexCircular1C(BaseNKModel):
|
||||
a_set = models.ManyToManyField("M2MComplexCircular1A",
|
||||
through="M2MCircular1ThroughCA")
|
||||
|
||||
|
||||
class M2MCircular1ThroughAB(BaseNKModel):
|
||||
a = models.ForeignKey(M2MComplexCircular1A)
|
||||
b = models.ForeignKey(M2MComplexCircular1B)
|
||||
|
||||
|
||||
class M2MCircular1ThroughBC(BaseNKModel):
|
||||
b = models.ForeignKey(M2MComplexCircular1B)
|
||||
c = models.ForeignKey(M2MComplexCircular1C)
|
||||
|
||||
|
||||
class M2MCircular1ThroughCA(BaseNKModel):
|
||||
c = models.ForeignKey(M2MComplexCircular1C)
|
||||
a = models.ForeignKey(M2MComplexCircular1A)
|
||||
|
||||
|
||||
class M2MComplexCircular2A(BaseNKModel):
|
||||
b_set = models.ManyToManyField("M2MComplexCircular2B",
|
||||
through="M2MCircular2ThroughAB")
|
||||
|
||||
|
||||
class M2MComplexCircular2B(BaseNKModel):
|
||||
def natural_key(self):
|
||||
return (self.data,)
|
||||
# Fake the dependency for a circularity
|
||||
natural_key.dependencies = ["fixtures_regress.M2MComplexCircular2A"]
|
||||
|
||||
|
||||
class M2MCircular2ThroughAB(BaseNKModel):
|
||||
a = models.ForeignKey(M2MComplexCircular2A)
|
||||
b = models.ForeignKey(M2MComplexCircular2B)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue