Browse files

Fixed #19273 -- DB cache backend on Postgres 9.0+ and py3 works again

There was a problem caused by Postgres 9.0+ having bytea_output default
value of 'hex' and cache backend inserting the content to be cached as
'bytes' value into a column of type TEXT. Fixed by converting the bytes
value to a string before insert.
  • Loading branch information...
akaariai committed Nov 10, 2012
1 parent 04a7ea3 commit b07ae5ec84acaa1ecffc74ade51c4564632ca869
Showing with 3 additions and 1 deletion.
  1. +3 −1 django/core/cache/backends/
@@ -104,7 +104,9 @@ def _base_set(self, mode, key, value, timeout=None):
if num > self._max_entries:
self._cull(db, cursor, now)
pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)
- encoded = base64.b64encode(pickled).strip()
+ # Convert to base64. Make sure the value is a string, as the
+ # db column is a string (not byte) column.
+ encoded = base64.b64encode(pickled).decode('latin1')
cursor.execute("SELECT cache_key, expires FROM %s "
"WHERE cache_key = %%s" % table, [key])

0 comments on commit b07ae5e

Please sign in to comment.