Refs #20892 -- Removed support for passing pylibmc behavior settings as top-level attributes of CACHES['OPTIONS'].

Per deprecation timeline.
This commit is contained in:
Tim Graham 2017-09-02 19:59:45 -04:00
parent 87d2240e6c
commit e47b56d791
4 changed files with 3 additions and 47 deletions

View File

@ -3,10 +3,8 @@
import pickle import pickle
import re import re
import time import time
import warnings
from django.core.cache.backends.base import DEFAULT_TIMEOUT, BaseCache from django.core.cache.backends.base import DEFAULT_TIMEOUT, BaseCache
from django.utils.deprecation import RemovedInDjango21Warning
from django.utils.functional import cached_property from django.utils.functional import cached_property
@ -171,25 +169,6 @@ class PyLibMCCache(BaseMemcachedCache):
import pylibmc import pylibmc
super().__init__(server, params, library=pylibmc, value_not_found_exception=pylibmc.NotFound) super().__init__(server, params, library=pylibmc, value_not_found_exception=pylibmc.NotFound)
# The contents of `OPTIONS` was formerly only used to set the behaviors
# attribute, but is now passed directly to the Client constructor. As such,
# any options that don't match a valid keyword argument are removed and set
# under the `behaviors` key instead, to maintain backwards compatibility.
legacy_behaviors = {}
for option in list(self._options):
if option not in ('behaviors', 'binary', 'username', 'password'):
warnings.warn(
"Specifying pylibmc cache behaviors as a top-level property "
"within `OPTIONS` is deprecated. Move `%s` into a dict named "
"`behaviors` inside `OPTIONS` instead." % option,
RemovedInDjango21Warning,
stacklevel=2,
)
legacy_behaviors[option] = self._options.pop(option)
if legacy_behaviors:
self._options.setdefault('behaviors', {}).update(legacy_behaviors)
@cached_property @cached_property
def _cache(self): def _cache(self):
return self._lib.Client(self._servers, **self._options) return self._lib.Client(self._servers, **self._options)

View File

@ -236,3 +236,6 @@ how to remove usage of these features.
* ``django.test.runner.setup_databases()`` is removed. * ``django.test.runner.setup_databases()`` is removed.
* ``django.utils.translation.string_concat()`` is removed. * ``django.utils.translation.string_concat()`` is removed.
* ``django.core.cache.backends.memcached.PyLibMCCache`` no longer supports
passing ``pylibmc`` behavior settings as top-level attributes of ``OPTIONS``.

View File

@ -479,14 +479,6 @@ the binary protocol, SASL authentication, and the ``ketama`` behavior mode::
} }
} }
.. versionchanged:: 1.11
Memcached backends can now be configured using ``OPTIONS``.
In older versions, you could pass ``pylibmc`` behavior settings directly
inside ``OPTIONS``. This is deprecated in favor of setting them under a
``behaviors`` key within ``OPTIONS`` instead.
.. _the-per-site-cache: .. _the-per-site-cache:
The per-site cache The per-site cache

18
tests/cache/tests.py vendored
View File

@ -1308,24 +1308,6 @@ class PyLibMCCacheTests(BaseMemcachedTests, TestCase):
self.assertTrue(cache._cache.binary) self.assertTrue(cache._cache.binary)
self.assertEqual(cache._cache.behaviors['tcp_nodelay'], int(True)) self.assertEqual(cache._cache.behaviors['tcp_nodelay'], int(True))
@override_settings(CACHES=caches_setting_for_tests(
base=PyLibMCCache_params,
exclude=memcached_excluded_caches,
OPTIONS={'tcp_nodelay': True},
))
def test_pylibmc_legacy_options(self):
deprecation_message = (
"Specifying pylibmc cache behaviors as a top-level property "
"within `OPTIONS` is deprecated. Move `tcp_nodelay` into a dict named "
"`behaviors` inside `OPTIONS` instead."
)
with warnings.catch_warnings(record=True) as warns:
warnings.simplefilter("always")
self.assertEqual(cache._cache.behaviors['tcp_nodelay'], int(True))
self.assertEqual(len(warns), 1)
self.assertIsInstance(warns[0].message, RemovedInDjango21Warning)
self.assertEqual(str(warns[0].message), deprecation_message)
@override_settings(CACHES=caches_setting_for_tests( @override_settings(CACHES=caches_setting_for_tests(
BACKEND='django.core.cache.backends.filebased.FileBasedCache', BACKEND='django.core.cache.backends.filebased.FileBasedCache',