Code

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#13622 closed (worksforme)

Caching unicode characters with Memcached no longer works

Reported by: Chris Targett <chris@…> 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: UI/UX:

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.

Attachments (0)

Change History (2)

comment:1 Changed 4 years ago by erikr

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to worksforme
  • Status changed from new to closed
  • Triage Stage changed from Unreviewed to Accepted

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.

comment:2 Changed 4 years ago by kmtracey

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.