diff options
| author | Simon Charette <charette.s@gmail.com> | 2024-08-09 12:55:40 -0400 |
|---|---|---|
| committer | Natalia <124304+nessita@users.noreply.github.com> | 2024-08-28 11:46:49 -0300 |
| commit | dd58edcc373afe57a56bf7c2374a4fc8446e80e9 (patch) | |
| tree | fe9d42a4d476ec4045f77202823fe6edc2f51312 | |
| parent | 8f5d2c374a150fca063443292cdf2618026bda42 (diff) | |
[5.1.x] Refs #35405 -- Adjusted deprecation warning stacklevel in FieldCacheMixin.get_cache_name().
Backport of 39abd56a7fb1e2f735040df0fdfc08f57d91a49b from main.
| -rw-r--r-- | django/db/models/fields/mixins.py | 1 | ||||
| -rw-r--r-- | docs/releases/5.1.1.txt | 4 | ||||
| -rw-r--r-- | tests/model_fields/test_mixins.py | 3 |
3 files changed, 7 insertions, 1 deletions
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 |
