Skip to content

Commit 34818c3

Browse files
0xDEC0DEzzzeek
authored andcommitted
fix: make dogpile.cache.memory preserve its init parameters
Make the `MemoryBackend` behave like the others, and stop removing keys from the initialization dict. Fixes: #273 Closes: #274 Pull-request: #274 Pull-request-sha: b893879 Change-Id: Ifd3f0d88b18a73a0ce287e1a514a6268daf157c4
1 parent 424627d commit 34818c3

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

docs/build/unreleased/273.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.. change::
2+
:tags: bug, memory
3+
:tickets: 273
4+
5+
Fixed issue where :meth:`.MemoryBackend.configure` would unexpectedly
6+
modify the input arguments dictionary by removing its contents. The method
7+
now preserves the original arguments dictionary as expected, consistent
8+
with the behavior of other backend types. Pull request courtesy Nicolas
9+
Simonds.

dogpile/cache/backends/memory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class MemoryBackend(CacheBackend):
5050
"""
5151

5252
def __init__(self, arguments):
53-
self._cache = arguments.pop("cache_dict", {})
53+
self._cache = arguments.get("cache_dict", {})
5454

5555
def get(self, key):
5656
return self._cache.get(key, NO_VALUE)

dogpile/testing/fixtures.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ def teardown_method(self, method):
5050
def _check_backend_available(cls, backend):
5151
pass
5252

53+
backend: str
5354
region_args = {}
5455
config_args = {}
5556
extra_arguments = {}
57+
backend_argument_names = ()
5658

5759
_region_inst = None
5860
_backend_inst = None
@@ -398,6 +400,33 @@ def boom():
398400
Exception, "boom", reg.get_or_create, some_key, boom
399401
)
400402

403+
def test_argument_dictionary_unmodified(self):
404+
fixed_arg_names = getattr(self, "backend_argument_names", None)
405+
406+
backend_arguments = {}
407+
if not fixed_arg_names:
408+
backend_arguments.update(self.config_args["arguments"])
409+
else:
410+
backend_arguments.update(
411+
{key: "somevalue" for key in self.backend_argument_names}
412+
)
413+
414+
assert backend_arguments, (
415+
"suite has no config_args['arguments'] and no "
416+
"backend_argument_names attribute I can use to generate an "
417+
"arg dict"
418+
)
419+
420+
backend_arguments.update(
421+
{"arbitrary_arg_one": "foo", "arbitrary_arg_two": "bar"}
422+
)
423+
argument_dict_copy = dict(backend_arguments)
424+
425+
region = CacheRegion()
426+
region.configure(self.backend, arguments=backend_arguments)
427+
428+
eq_(backend_arguments, argument_dict_copy)
429+
401430

402431
def raise_cant_deserialize_exception(v):
403432
raise CantDeserializeException()

tests/cache/test_memory_backend.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
class MemoryBackendTest(_GenericBackendTestSuite):
66
backend = "dogpile.cache.memory"
7+
backend_argument_names = ["cache_dict"]
78

89

910
class MemoryBackendSerializerTest(
@@ -12,5 +13,5 @@ class MemoryBackendSerializerTest(
1213
pass
1314

1415

15-
class MemoryPickleBackendTest(_GenericBackendTestSuite):
16+
class MemoryPickleBackendTest(MemoryBackendTest):
1617
backend = "dogpile.cache.memory_pickle"

0 commit comments

Comments
 (0)