mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #32833 -- Fixed ContentTypeManager.get_for_models() crash when using in migrations.
Co-authored-by: Heraldo Lucena <23155511+HMaker@users.noreply.github.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user