From 39abd56a7fb1e2f735040df0fdfc08f57d91a49b Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Fri, 9 Aug 2024 12:55:40 -0400 Subject: [PATCH] Refs #35405 -- Adjusted deprecation warning stacklevel in FieldCacheMixin.get_cache_name(). --- django/db/models/fields/mixins.py | 1 + docs/releases/5.1.1.txt | 4 ++++ tests/model_fields/test_mixins.py | 3 ++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/django/db/models/fields/mixins.py b/django/db/models/fields/mixins.py index 9f2809dfc8..6774303773 100644 --- a/django/db/models/fields/mixins.py +++ b/django/db/models/fields/mixins.py @@ -28,6 +28,7 @@ class FieldCacheMixin: f"Override {self.__class__.__qualname__}.cache_name instead of " "get_cache_name().", RemovedInDjango60Warning, + stacklevel=3, ) return cache_name diff --git a/docs/releases/5.1.1.txt b/docs/releases/5.1.1.txt index 82a7aed1c8..b6f9d23c35 100644 --- a/docs/releases/5.1.1.txt +++ b/docs/releases/5.1.1.txt @@ -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`). diff --git a/tests/model_fields/test_mixins.py b/tests/model_fields/test_mixins.py index 5ccfac4d78..8847f25987 100644 --- a/tests/model_fields/test_mixins.py +++ b/tests/model_fields/test_mixins.py @@ -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