[Zope3-dev] Psycopgda adapter, should _conv_str do NULL check?
Carroll Kong
me at carrollkong.com
Wed Oct 13 07:58:48 EDT 2004
In psycopgda module rev 27872, adapter.py ~line 266
The original code just converts strings passed to _conv_string into unicode.
def _conv_string(str):
return str.decode(PG_ENCODING)
However, if I have a NULL field in the database, then str.decode fails with
AttributeError: 'NoneType' object has no attribute 'decode'
This isn't the same as a '' string (in which case the decode would work), or
at least my psycopgda driver (1.1.14 ) and postgresl version (7.4.1) didn't
seem to believe so. (I had an optional field and it was empty before I put
on constraints to add default values).
I suppose you could argue that one should always use strong default values
into the database. I am not as familiar with the code, but I added this to
psycopgda's adapter.py.
def _conv_string(str):
if str:
return str.decode(PG_ENCODING)
else:
return None
Not sure if that's going to cause problems or not. My prelim testing seems
to show it will work, or I could just always use default values so there are
no NULL optional fields.
- Carroll Kong
More information about the Zope3-dev
mailing list