From ba6f83ec95dbd265ae3d493c8d6375f36052d12e Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Fri, 18 Dec 2015 14:49:23 -0500 Subject: [1.9.x] Fixed #26286 -- Prevented content type managers from sharing their cache. This should prevent managers methods from returning content type instances registered to foreign apps now that these managers are also attached to models created during migration phases. Thanks Tim for the review. Refs #23822. Backport of 3938b3ccaa85f1c366909a4839696007726a09da from master --- tests/contenttypes_tests/test_models.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/contenttypes_tests/test_models.py b/tests/contenttypes_tests/test_models.py index eb436b6a64..75cea0a4d8 100644 --- a/tests/contenttypes_tests/test_models.py +++ b/tests/contenttypes_tests/test_models.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals import warnings -from django.contrib.contenttypes.models import ContentType +from django.contrib.contenttypes.models import ContentType, ContentTypeManager from django.contrib.contenttypes.views import shortcut from django.contrib.sites.shortcuts import get_current_site from django.db.utils import IntegrityError, OperationalError, ProgrammingError @@ -170,6 +170,18 @@ class ContentTypesTests(TestCase): DeferredProxyModel: proxy_model_ct, }) + def test_cache_not_shared_between_managers(self): + with self.assertNumQueries(1): + ContentType.objects.get_for_model(ContentType) + with self.assertNumQueries(0): + ContentType.objects.get_for_model(ContentType) + other_manager = ContentTypeManager() + other_manager.model = ContentType + with self.assertNumQueries(1): + other_manager.get_for_model(ContentType) + with self.assertNumQueries(0): + other_manager.get_for_model(ContentType) + @override_settings(ALLOWED_HOSTS=['example.com']) def test_shortcut_view(self): """ -- cgit v1.3