mirror of
https://github.com/django/django.git
synced 2025-05-04 22:17:34 +00:00
Refs #35405 -- Removed FieldCacheMixin.get_cache_name() per deprecation timeline.
This commit is contained in:
parent
85750bd2f8
commit
bc3f3031d8
@ -1,7 +1,4 @@
|
|||||||
import warnings
|
|
||||||
|
|
||||||
from django.core import checks
|
from django.core import checks
|
||||||
from django.utils.deprecation import RemovedInDjango60Warning
|
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
|
|
||||||
NOT_PROVIDED = object()
|
NOT_PROVIDED = object()
|
||||||
@ -15,22 +12,9 @@ class FieldCacheMixin:
|
|||||||
typically the field’s name.
|
typically the field’s name.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# RemovedInDjango60Warning.
|
|
||||||
def get_cache_name(self):
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def cache_name(self):
|
def cache_name(self):
|
||||||
# RemovedInDjango60Warning: when the deprecation ends, replace with:
|
raise NotImplementedError
|
||||||
# raise NotImplementedError
|
|
||||||
cache_name = self.get_cache_name()
|
|
||||||
warnings.warn(
|
|
||||||
f"Override {self.__class__.__qualname__}.cache_name instead of "
|
|
||||||
"get_cache_name().",
|
|
||||||
RemovedInDjango60Warning,
|
|
||||||
stacklevel=3,
|
|
||||||
)
|
|
||||||
return cache_name
|
|
||||||
|
|
||||||
def get_cached_value(self, instance, default=NOT_PROVIDED):
|
def get_cached_value(self, instance, default=NOT_PROVIDED):
|
||||||
try:
|
try:
|
||||||
|
@ -316,3 +316,5 @@ to remove usage of these features.
|
|||||||
* The setter for ``django.contrib.gis.gdal.OGRGeometry.coord_dim`` is removed.
|
* The setter for ``django.contrib.gis.gdal.OGRGeometry.coord_dim`` is removed.
|
||||||
|
|
||||||
* The ``check`` keyword argument of ``CheckConstraint`` is removed.
|
* The ``check`` keyword argument of ``CheckConstraint`` is removed.
|
||||||
|
|
||||||
|
* The ``get_cache_name()`` method of ``FieldCacheMixin`` is removed.
|
||||||
|
@ -1,17 +1,10 @@
|
|||||||
from django.db.models.fields.mixins import FieldCacheMixin
|
from django.db.models.fields.mixins import FieldCacheMixin
|
||||||
from django.test import SimpleTestCase
|
from django.test import SimpleTestCase
|
||||||
from django.utils.deprecation import RemovedInDjango60Warning
|
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
|
|
||||||
from .models import Foo
|
from .models import Foo
|
||||||
|
|
||||||
|
|
||||||
# RemovedInDjango60Warning.
|
|
||||||
class ExampleOld(FieldCacheMixin):
|
|
||||||
def get_cache_name(self):
|
|
||||||
return "example"
|
|
||||||
|
|
||||||
|
|
||||||
class Example(FieldCacheMixin):
|
class Example(FieldCacheMixin):
|
||||||
@cached_property
|
@cached_property
|
||||||
def cache_name(self):
|
def cache_name(self):
|
||||||
@ -23,21 +16,9 @@ class FieldCacheMixinTests(SimpleTestCase):
|
|||||||
self.instance = Foo()
|
self.instance = Foo()
|
||||||
self.field = Example()
|
self.field = Example()
|
||||||
|
|
||||||
# RemovedInDjango60Warning: when the deprecation ends, replace with:
|
def test_cache_name_not_implemented(self):
|
||||||
# def test_cache_name_not_implemented(self):
|
|
||||||
# with self.assertRaises(NotImplementedError):
|
|
||||||
# FieldCacheMixin().cache_name
|
|
||||||
def test_get_cache_name_not_implemented(self):
|
|
||||||
with self.assertRaises(NotImplementedError):
|
with self.assertRaises(NotImplementedError):
|
||||||
FieldCacheMixin().get_cache_name()
|
FieldCacheMixin().cache_name
|
||||||
|
|
||||||
# RemovedInDjango60Warning.
|
|
||||||
def test_get_cache_name_deprecated(self):
|
|
||||||
msg = "Override ExampleOld.cache_name instead of get_cache_name()."
|
|
||||||
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):
|
def test_cache_name(self):
|
||||||
result = Example().cache_name
|
result = Example().cache_name
|
||||||
|
Loading…
x
Reference in New Issue
Block a user