summaryrefslogtreecommitdiff
path: root/tests/contenttypes_tests
diff options
context:
space:
mode:
authorSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-06-21 14:24:25 +0200
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-06-24 10:20:11 +0200
commitf1705c8780c0a7587654fc736542d55fe4a7f29b (patch)
treea6155bda765e391336773257921e894c11a3e1d1 /tests/contenttypes_tests
parent2a082d827de05528cb976109f219ec9b00490d2d (diff)
Fixed #35545, Refs #32833 -- Fixed ContentTypeManager.get_for_models() crash in CreateModel migrations.
Thank you to Csirmaz Bendegúz for the report and Simon Charettes for the review.
Diffstat (limited to 'tests/contenttypes_tests')
-rw-r--r--tests/contenttypes_tests/test_models.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/tests/contenttypes_tests/test_models.py b/tests/contenttypes_tests/test_models.py
index 799f1cc58c..b63c57ef09 100644
--- a/tests/contenttypes_tests/test_models.py
+++ b/tests/contenttypes_tests/test_models.py
@@ -2,7 +2,7 @@ from django.apps import apps
from django.contrib.contenttypes.models import ContentType, ContentTypeManager
from django.contrib.contenttypes.prefetch import GenericPrefetch
from django.db import models
-from django.db.migrations.state import ProjectState
+from django.db.migrations.state import ModelState, ProjectState
from django.test import TestCase, override_settings
from django.test.utils import isolate_apps
@@ -99,6 +99,25 @@ class ContentTypesTests(TestCase):
cts, {ContentType: ContentType.objects.get_for_model(ContentType)}
)
+ @isolate_apps("contenttypes_tests")
+ def test_get_for_models_migrations_create_model(self):
+ state = ProjectState.from_apps(apps.get_app_config("contenttypes"))
+
+ class Foo(models.Model):
+ class Meta:
+ app_label = "contenttypes_tests"
+
+ state.add_model(ModelState.from_model(Foo))
+ ContentType = state.apps.get_model("contenttypes", "ContentType")
+ cts = ContentType.objects.get_for_models(FooWithUrl, Foo)
+ self.assertEqual(
+ cts,
+ {
+ Foo: ContentType.objects.get_for_model(Foo),
+ FooWithUrl: ContentType.objects.get_for_model(FooWithUrl),
+ },
+ )
+
def test_get_for_models_full_cache(self):
# Full cache
ContentType.objects.get_for_model(ContentType)