summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlton Gibson <carlton.gibson@noumenal.es>2025-12-11 10:05:51 +0100
committerJacob Walls <jacobtylerwalls@gmail.com>2025-12-11 12:35:16 -0500
commit0129f40bef94b192fc9edcbe20a10c3b4b02f820 (patch)
treefd6ad465a279cdbaceb2d61bc910a99e22f407ec
parent2b808d567de43d8ec591d9eb688ae66055e3aefc (diff)
[6.0.x] Noted testing uses for ContentTypeManager.clear_cache() method.
It is often necessary to reset the cache between tests, or after preparing test state, when using content types. Django's test suite already does this when needed, but users will need to do similar in their own tests. Backport of 37eb8909699d261b9b879e6f04dbfeec75b5e080 from main.
-rw-r--r--docs/ref/contrib/contenttypes.txt12
1 files changed, 10 insertions, 2 deletions
diff --git a/docs/ref/contrib/contenttypes.txt b/docs/ref/contrib/contenttypes.txt
index 72bee36a08..3195253dbf 100644
--- a/docs/ref/contrib/contenttypes.txt
+++ b/docs/ref/contrib/contenttypes.txt
@@ -183,8 +183,16 @@ The ``ContentTypeManager``
:class:`~django.contrib.contenttypes.models.ContentType` to keep track
of models for which it has created
:class:`~django.contrib.contenttypes.models.ContentType` instances. You
- probably won't ever need to call this method yourself; Django will call
- it automatically when it's needed.
+ probably won't need to call this method in application code yourself;
+ Django will call it automatically when it's needed.
+
+ You may need to clear the cache when testing, to reset between tests,
+ or after preparing test state. For example::
+
+ class ContentTypesTests(TestCase):
+ def setUp(self):
+ ContentType.objects.clear_cache()
+ self.addCleanup(ContentType.objects.clear_cache)
.. method:: get_for_id(id)