pgsql driver fails when sql string is actually unicode
chadwhitacre opened this issue · comments
If I pass a unicode object to simplequery, I get an error from line 111 of pgsql.py. Traceback:
File ".../diesel/protocols/pgsql.py", line 111, in send
tosend = self.idbyte + struct.pack('!I', len(allbytes)+4) + allbytes
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa1 in position 4: ordinal not in range(128)
This is because the struct.pack() output is being implicitly coerced to ascii by the concatenation with the unicode allbytes. Presumably the rest of the module should be checked for this bug as well. The workaround is to encode sql to str before passing to simplequery, like so:
sql = sql.encode('ascii')
IIRC (and it's been awhile.. http://jamwt.com/pgasync/ ) the postgres wire spec expects utf-8, so it's reasonable on the client library side to encode('utf-8') unicode strings that are passed in. I'll tackle this at some point.
This implementation of the postgres protocol doesn't exist anymore.