Fixed #25040 -- Fixed migrations state crash with GenericForeignKey
This commit is contained in:
parent
11cac1bd8e
commit
60f795c060
|
@ -43,7 +43,7 @@ def get_related_models_recursive(model):
|
||||||
def _related_models(m):
|
def _related_models(m):
|
||||||
return [
|
return [
|
||||||
f.related_model for f in m._meta.get_fields(include_parents=True, include_hidden=True)
|
f.related_model for f in m._meta.get_fields(include_parents=True, include_hidden=True)
|
||||||
if f.is_relation and not isinstance(f.related_model, six.string_types)
|
if f.is_relation and f.related_model is not None and not isinstance(f.related_model, six.string_types)
|
||||||
] + [
|
] + [
|
||||||
subclass for subclass in m.__subclasses__()
|
subclass for subclass in m.__subclasses__()
|
||||||
if issubclass(subclass, models.Model)
|
if issubclass(subclass, models.Model)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from django.apps.registry import Apps
|
from django.apps.registry import Apps
|
||||||
|
from django.contrib.contenttypes.fields import GenericForeignKey
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.migrations.exceptions import InvalidBasesError
|
from django.db.migrations.exceptions import InvalidBasesError
|
||||||
from django.db.migrations.operations import (
|
from django.db.migrations.operations import (
|
||||||
|
@ -1049,6 +1050,12 @@ class RelatedModelsTests(SimpleTestCase):
|
||||||
self.assertRelated(S, [A, B, T])
|
self.assertRelated(S, [A, B, T])
|
||||||
self.assertRelated(T, [A, B, S])
|
self.assertRelated(T, [A, B, S])
|
||||||
|
|
||||||
|
def test_generic_fk(self):
|
||||||
|
A = self.create_model("A", foreign_keys=[models.ForeignKey('B'), GenericForeignKey()])
|
||||||
|
B = self.create_model("B", foreign_keys=[models.ForeignKey('C')])
|
||||||
|
self.assertRelated(A, [B])
|
||||||
|
self.assertRelated(B, [A])
|
||||||
|
|
||||||
def test_abstract_base(self):
|
def test_abstract_base(self):
|
||||||
A = self.create_model("A", abstract=True)
|
A = self.create_model("A", abstract=True)
|
||||||
B = self.create_model("B", bases=(A,))
|
B = self.create_model("B", bases=(A,))
|
||||||
|
|
Loading…
Reference in New Issue