Opened 8 years ago

Closed 7 years ago

Last modified 6 years ago

#5589 closed (invalid)

Memcache backend should allow retrieval of stored binary objects

Reported by: jhenry <jhenry@…> Owned by: nobody
Component: Core (Cache system) Version: master
Severity: Keywords:
Cc: mitsuhiko, dan@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: UI/UX:

Description

Currently, the memcache backend is calling smart_unicode() on the output of the cache. This is not correct behavior, as there is no documentation saying that only unicode data can and should be stored in the cache. Theoretically any bytestream should be able to be stored in the cache.

The use case that I am working with in particular is a captcha generator. I was able to store the captcha image data generated with PIL in the cache, but on retrieval, I got a UnicodeDecodeError.

If the unicode restriction is intended, there should be an error on insert as well.

I have a patch to allow binary objects to be retrieved from the memcache backend if the unicode decode fails.

Attachments (1)

allow_binary_data_in_memcache.diff (578 bytes) - added by jhenry <jhenry@…> 8 years ago.

Download all attachments as: .zip

Change History (7)

Changed 8 years ago by jhenry <jhenry@…>

comment:1 Changed 8 years ago by Simon G <dev@…>

  • Component changed from Uncategorized to Cache system
  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 8 years ago by jacob

  • Needs tests set
  • Patch needs improvement set
  • Resolution set to fixed
  • Status changed from new to closed
  • Triage Stage changed from Design decision needed to Accepted

I'm not sure the patch behvaior is correct -- isn't that error sometimes useful? -- but indeed arbitrary objects should be storeable.

comment:3 Changed 7 years ago by mitsuhiko

  • Resolution fixed deleted
  • Status changed from closed to reopened

This is still broken...

comment:4 Changed 7 years ago by mitsuhiko

  • Cc mitsuhiko added

comment:5 Changed 7 years ago by PhiR

  • Resolution set to invalid
  • Status changed from reopened to closed

The patch behavior is erroneous. The current code tests isinstance(basestring) and will return the value as-is for any other class. So if you want to store a binary object you just need to avoid using strings. Anything that is pickle'able will work.

comment:6 Changed 6 years ago by danros

  • Cc dan@… added
Note: See TracTickets for help on using tickets.
Back to Top