summaryrefslogtreecommitdiff
path: root/tests/contenttypes_tests
diff options
context:
space:
mode:
authorSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2022-10-10 08:57:52 +0200
committerGitHub <noreply@github.com>2022-10-10 08:57:52 +0200
commit84206607d6bfd61e7f7a88b51163ffd4153e3b5a (patch)
tree502b1a49b84539637ba2bdf050fa8d566cc47a6b /tests/contenttypes_tests
parentd3579ca1124a163cad760558e8d138984e7a10b4 (diff)
Fixed #32833 -- Fixed ContentTypeManager.get_for_models() crash when using in migrations.
Co-authored-by: Heraldo Lucena <23155511+HMaker@users.noreply.github.com>
Diffstat (limited to 'tests/contenttypes_tests')
-rw-r--r--tests/contenttypes_tests/test_models.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/contenttypes_tests/test_models.py b/tests/contenttypes_tests/test_models.py
index 2741556df7..d0aa08dd22 100644
--- a/tests/contenttypes_tests/test_models.py
+++ b/tests/contenttypes_tests/test_models.py
@@ -1,5 +1,7 @@
+from django.apps import apps
from django.contrib.contenttypes.models import ContentType, ContentTypeManager
from django.db import models
+from django.db.migrations.state import ProjectState
from django.test import TestCase, override_settings
from django.test.utils import isolate_apps
@@ -90,6 +92,14 @@ class ContentTypesTests(TestCase):
},
)
+ def test_get_for_models_migrations(self):
+ state = ProjectState.from_apps(apps.get_app_config("contenttypes"))
+ ContentType = state.apps.get_model("contenttypes", "ContentType")
+ cts = ContentType.objects.get_for_models(ContentType)
+ self.assertEqual(
+ cts, {ContentType: ContentType.objects.get_for_model(ContentType)}
+ )
+
def test_get_for_models_full_cache(self):
# Full cache
ContentType.objects.get_for_model(ContentType)