> That's a feature, not a bug. There are actually no special "unicode"
>
Thanks for the reply! I understand your reasoning, and since there's a few
workarounds it's not really an issue for me any more, but there's a few
extra things I wanted to note:
- PyGreSQL happily accepts unicode() as input but only provides str() as
output. This is an unexpected asymmetry which isn't present in the other
major Python/Postgres interface (Psycopg). In a sense, therefore,PyGreSQL
is not really a transparent interface but rather a transforming one.
- I discovered this behavior when I tried to use PyGreSQL as the backend
driver in a Django instance. The MySQL, Oracle, and Psycopg database
backends all worked "as is" without any modification. When we used
PyGreSQL, Django objects were reporting corrupted Unicode, and indeed
crashed when trying to do a simple read-noop-write roundtrip:
>>> UnicodeObject.objects.get(column_id='key')
<UnicodeObject: [Bad Unicode data]>
>>> UnicodeObject.objects.get(column_id='key').save()
...
OperationalError: ... 'ascii' codec can't decode byte 0xe2 in position
3: ordinal not in range(128)
These issues disappeared after installing the custom typecasts.
- It might be worth specifically calling out the str()/unicode()/Python2.x
issue in the documentation. I spent some time looking through the docs, and
even saw the table you pointed me at, but I never connected the two as
related. That might just be a failure on my part, but it wouldn't hurt to
have it more clearly spelt out. Specifically, it might be good to have a
"Unicode" section explaining the rationale for the asymmetrical behavior,
the fact that it works differently in Python 3 vs 2, and showing how to use
the "set_typecast" workaround to get unicode() results.
- I'm using PyGreSQL because the "official" Postgres driver mentioned in
the Django documentation has a license I don't want to use. You may want to
consider reaching out to the Django people to list your library as an
alternative (and provide a shim that addresses the asymmetry/crash). I'm
sure plenty of people would love to use your software, if only it was
easier to find and use with Django!
Thanks again,
Murray
_______________________________________________
PyGreSQL mailing list
[email protected]
https://mail.vex.net/mailman/listinfo.cgi/pygresql