Refs #35405 -- Adjusted deprecation warning stacklevel in FieldCacheMixin.get_cache_name().

This commit is contained in:
Simon Charette 2024-08-09 12:55:40 -04:00 committed by nessita
parent 47f18a7226
commit 39abd56a7f
3 changed files with 7 additions and 1 deletions

View File

@ -28,6 +28,7 @@ class FieldCacheMixin:
f"Override {self.__class__.__qualname__}.cache_name instead of "
"get_cache_name().",
RemovedInDjango60Warning,
stacklevel=3,
)
return cache_name

View File

@ -27,3 +27,7 @@ Bugfixes
* Adjusted the deprecation warning ``stacklevel`` when using ``OS_OPEN_FLAGS``
in :class:`~django.core.files.storage.FileSystemStorage` to correctly point
to the offending call site (:ticket:`35326`).
* Adjusted the deprecation warning ``stacklevel`` in
``FieldCacheMixin.get_cache_name()`` to correctly point to the offending call
site (:ticket:`35405`).

View File

@ -34,9 +34,10 @@ class FieldCacheMixinTests(SimpleTestCase):
# RemovedInDjango60Warning.
def test_get_cache_name_deprecated(self):
msg = "Override ExampleOld.cache_name instead of get_cache_name()."
with self.assertWarnsMessage(RemovedInDjango60Warning, msg):
with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
result = ExampleOld().cache_name
self.assertEqual(result, "example")
self.assertEqual(ctx.filename, __file__)
def test_cache_name(self):
result = Example().cache_name