PostgreSQL 9.0 cache db backend doesn't work on py3
|Reported by:||akaariai||Owned by:||nobody|
|Component:||Core (Cache system)||Version:||1.5-alpha-1|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
PostgreSQL + 9.0 + cache db backend doesn't work on python 3.
The reason for this is that base64 encoding a string returns bytes on py3, PostgreSQL 9.0 has hex output type conversion on by default for byte values, and the column we are inserting into is TEXT. So, psycopg2 gets a string "abc" and converts this to "hex encoding" ('\x616263'). However as the column is of type text this is inserted directly as string '\x616263' into the column. When we fetch it back we get a string containing '\x616263', not bytes containing "abc". This results in exception when trying to base64 decode the value.
On PostgreSQL versions earlier than 9.0 the default byte encoding style was 'encoded', which means we insert the "abc" as string 'abc' and everything works.
The solution is to insert the string "abc" into the DB, not bytes('abc'). Will post a patch soon...