#13622 closed (worksforme)
Caching unicode characters with Memcached no longer works
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | Core (Cache system) | Version: | 1.2 |
| Severity: | Keywords: | memcached | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Since updating to Django 1.2.0 I am no longer able to cache unicode characters using the Memcached backend.
>>> from django import VERSION
>>> VERSION
(1, 1, 1, 'final', 0)
>>> import memcache
>>> memcache.__version__
'1.31'
>>>
>>> from django.core.cache import cache
>>> cache.set('test_key', u'\u2026')
>>> cache.get('test_key')
u'\u2026'
>>>
>>> from django import VERSION
>>> VERSION
(1, 2, 0, 'final', 0)
>>> import memcache
>>> memcache.__version__
'1.31'
>>>
>>> from django.core.cache import cache
>>> cache.set('test_key', u'\u2026')
Traceback (most recent call last):
File "<console>", line 1, in ?
File "/export/www/wwwroot/staging/django/staging6/code/valiant/core/cache/backends/prefix_wrapper.py", line 39, in set
return self.backend.set(key, value, timeout)
File "/export/www/wwwroot/staging/django/staging6/code/django/core/cache/backends/memcached.py", line 54, in set
self._cache.set(smart_str(key), value, self._get_memcache_timeout(timeout))
File "/usr/lib/python2.4/site-packages/memcache.py", line 293, in set
return self._set("set", key, val, time)
File "/usr/lib/python2.4/site-packages/memcache.py", line 317, in _set
server.send_cmd(fullcmd)
File "/usr/lib/python2.4/site-packages/memcache.py", line 507, in send_cmd
self.socket.sendall(cmd + '\r\n')
File "<string>", line 1, in sendall
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2026' in position 40: ordinal not in range(128)
>>>
After reverting the changes here http://code.djangoproject.com/changeset/12637/django/trunk/django/core/cache/backends/memcached.py things seem to work again.
Change History (2)
comment:1 by , 15 years ago
| Resolution: | → worksforme |
|---|---|
| Status: | new → closed |
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 15 years ago
This may be a problem specific to using the old (now deprecated and unmaintained) cmemcache bindings. If you are using those old bindings you should switch to python-memcached, see: http://docs.djangoproject.com/en/dev/topics/cache/#memcached.
Note:
See TracTickets
for help on using tickets.
Testing with django trunk, but a more recent version of the memcached module, it works:
>>> from django import VERSION >>> VERSION (1, 2, 1, 'alpha', 0) >>> import memcache >>> memcache.__version__ '1.45' >>> from django.core.cache import cache >>> cache.set('test_key', u'\u2026') >>> cache.get('test_key') u'\u2026'So I guess your memcached module is too old, or this was fixed after 1.2 release.
Closing as worksforme.