﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31140	Caching of dict containing SafeText objects fails with bmemcached.	Hugo Rodger-Brown	nobody	"Not sure if this is a Django issue per se. but we have recently started having an issue where `cache.set` is failing where we have certain `SafeText` objects inside a dict. (Issue has already

The underlying exception is raised within `bmemcached`, but posting here in case someone else has had a similar issue, and any insight.


----

Expected behaviour - object can be cached:

{{{
>>> from django.utils.safestring import SafeString
>>> from django.core.cache import cache
>>> cache.set(""test"", SafeString(""foo""))
>>> cache.set(""test"", SafeString(""&pound;""))
}}}

Actual outcome - `cache.set` fails with a recursion error when the value being stored is a dict that contains a `SafeText` value.

{{{
>>> from django.utils.safestring import SafeString
>>> from django.core.cache import cache
>>> cache.set(""test"", {""foo"": SafeString(""&pound;"")})
Traceback (most recent call last):
  File ""/python3.7/site-packages/django/core/cache/backends/memcached.py"", line 78, in set
    if not self._cache.set(key, value, self.get_backend_timeout(timeout)):
  File ""/python3.7/site-packages/bmemcached/client/replicating.py"", line 112, in set
    returns.append(server.set(key, value, time, compress_level=compress_level))
  File ""/python3.7/site-packages/bmemcached/protocol.py"", line 604, in set
    return self._set_add_replace('set', key, value, time, compress_level=compress_level)
  File ""/python3.7/site-packages/bmemcached/protocol.py"", line 561, in _set_add_replace
    flags, value = self.serialize(value, compress_level=compress_level)
  File ""/python3.7/site-packages/bmemcached/protocol.py"", line 347, in serialize
    pickler.dump(value)
  File ""/python3.7/copyreg.py"", line 66, in _reduce_ex
    state = base(self)
RecursionError: maximum recursion depth exceeded while getting the str of an object
}}}


----


Running on Python 3.7, Django 2.2

Configuration:

{{{
CACHES = {
    ""default"": {
        ""BACKEND"": ""django_bmemcached.memcached.BMemcached"",
        ""BINARY"": True,
        ""OPTIONS"": {
            ""no_block"": True,
            ""tcp_nodelay"": True,
            ""tcp_keepalive"": True,
            ""remove_failed"": 4,
            ""retry_timeout"": 2,
            ""dead_timeout"": 10,
            ""_poll_timeout"": 2000,
        },
    },
}
}}}
"	Bug	closed	Core (Cache system)	2.2	Normal	invalid	cache bmemcached		Unreviewed	0	0	0	0	0	0
