[Zope3-Users] PsycopgDA problem

Dmitry Vasiliev lists at hlabs.spb.ru
Tue Mar 14 07:52:45 EST 2006


Stuart Bishop wrote:
> Dmitry Vasiliev wrote:
>> Also I've fixed broken tests, added CHANGES.txt and removed "utf-8"
>> encoding because it doesn't work for me. For now the only reliable way
>> to set encoding is through the configuration form.
> 
> What was broken with the Unicode support? This change is a regression as the
> client encoding is now stuck with whatever the default client encoding
> happens to be set to on the backend and allows the situation where the DA
> and the backend are attempting to talk totally different encodings.

It seems that 'SET client_encoding TO UNICODE' doesn't work as expected in our 
configuration (we use 'cp1251' encoded database for historical reasons) so we 
always got an UnicodeError with this option.

> If there is a reason you cannot communicate with your backend using UTF-8
> after setting the client encoding to UTF-8, then a better approach for the
> DA would be to query the client encoding and use that which avoids the
> possible mismatch (although this still means people are stuck using whatever
> the default encoding is on the backend).

MySQLDbDa already did this but some versions of MySQL returns wrong encoding 
name (see 
http://mail.zope.org/pipermail/zope3-users/2005-September/001033.html) so it 
was fixed to use getEncoding() method.

I think that input encoding name into the form not so big problem and moreover 
this solution works across different database versions.

>> And I really don't like error dispatching based on the error's message,
>> we need to redo error handling for psycopgda.
> 
> The only way of catching deadlock and serialization exceptions from psycopg
> is by sniffing the exceptions. psycopg2 might do this for us by raising more
> granular exceptions - I don't know. If it does, it will do so by sniffing
> the exception messages for us because I think this is all the PostgreSQL API
> gives you to work with (although thankfully the string is well documented,
> at least in the case of serialization exceptions).

PostgreSQL have well defined error codes (see 
http://www.postgresql.org/docs/8.1/static/errcodes-appendix.html for example) 
but unfortunately it seems you can get error code from exception only in psycopg2.

-- 
Dmitry Vasiliev (dima at hlabs.spb.ru)
     http://hlabs.spb.ru


More information about the Zope3-users mailing list