chtd / psycopg2cffi

Port to cffi with some speed improvements
Other
177 stars 43 forks source link

ascii decoding for database response #50

Closed Sunno closed 8 years ago

Sunno commented 9 years ago

Hi! I'm having an issue, in method "bytes_to_ascii" in _impl/adapters.py it throws an UnicodeDecodeError since database response has special characters (it's not in english), for instance in my error is:

 'ERROR:  llave duplicada viola restricción de unicidad «companies_requiredfield_branch_id_7e08660e8fafa825_uniq»
DETAIL:  Ya existe la llave (branch_id, field_id)=(2, 60).'

This database error is actually an integrity error (because an unique constraint), in my app (written in django) I capture it and send a message to user, but since I get an UnicodeDecodeError instead of an IntegrityError, for now I'll just validate it before trying to save.

I tried changing this line in _impl/adapters.py

return b.decode('ascii')

By

return b.decode('utf-8')

and it worked

lopuhin commented 8 years ago

@Sunno I think this is the same issue as a just recently fixed #56

lopuhin commented 8 years ago

2.7.3 release is on PyPI