Обсуждение: empty string in composite data types
Hi, I noticed some (imho) odd behaviour while using composite data types. Empty strings will be returned as None instead of '' in Python. For example: sql> CREATE TYPE testtype AS (id INT, label TEXT); python> import psycopg2 python> import psycopg2.extras python> db = psycopg2.connect(...) python> caster = psycopg2.extras.register_composite('testtype', db) python> cursor = db.cursor() python> cursor.execute("SELECT (1, '')::testtype") python> cursor.fetchone()[0] testtype(id=1, label=None) Is this behaviour intended? Or is there some flag I don't know about (I have found none) that gives me empty strings instead? Any help would be appreciated. Cheers, Chris
On Mon, Dec 3, 2012 at 12:15 PM, Christian von Kietzell <christian@vonkietzell.de> wrote: > Hi, > > I noticed some (imho) odd behaviour while using composite data types. > Empty strings will be returned as None instead of '' in Python. > > For example: > > sql> CREATE TYPE testtype AS (id INT, label TEXT); > > python> import psycopg2 > python> import psycopg2.extras > python> db = psycopg2.connect(...) > python> caster = psycopg2.extras.register_composite('testtype', db) > python> cursor = db.cursor() > python> cursor.execute("SELECT (1, '')::testtype") > python> cursor.fetchone()[0] > testtype(id=1, label=None) > > Is this behaviour intended? Or is there some flag I don't know about (I > have found none) that gives me empty strings instead? No, I'm afraid it's a bug. Could you please open a ticket in the tracker? I'll take a look at it this evening. -- Daniele
On Mon, Dec 3, 2012 at 12:49 PM, Daniele Varrazzo <daniele.varrazzo@gmail.com> wrote: > On Mon, Dec 3, 2012 at 12:15 PM, Christian von Kietzell > <christian@vonkietzell.de> wrote: >> Hi, >> >> I noticed some (imho) odd behaviour while using composite data types. >> Empty strings will be returned as None instead of '' in Python. >> >> For example: >> >> sql> CREATE TYPE testtype AS (id INT, label TEXT); >> >> python> import psycopg2 >> python> import psycopg2.extras >> python> db = psycopg2.connect(...) >> python> caster = psycopg2.extras.register_composite('testtype', db) >> python> cursor = db.cursor() >> python> cursor.execute("SELECT (1, '')::testtype") >> python> cursor.fetchone()[0] >> testtype(id=1, label=None) >> >> Is this behaviour intended? Or is there some flag I don't know about (I >> have found none) that gives me empty strings instead? > > No, I'm afraid it's a bug. Could you please open a ticket in the > tracker? I'll take a look at it this evening. Thank you for the report. Sorry for the stupid bug (https://github.com/dvarrazzo/psycopg/commit/9a031db8b90488afb59e0d6c8995398c88b6bc41). To be released in 2.4.6 (which is really due now). -- Daniele
On Mon, 2012-12-03 at 14:30 +0000, Daniele Varrazzo wrote: > =Thank you for the report. Sorry for the stupid bug > (https://github.com/dvarrazzo/psycopg/commit/9a031db8b90488afb59e0d6c8995398c88b6bc41). > > To be released in 2.4.6 (which is really due now). Thanks a lot for fixing it so quickly. That's why I love Free Software :) Chris
On Tue, Dec 4, 2012 at 9:15 AM, Christian von Kietzell <christian@vonkietzell.de> wrote:
--
On Mon, 2012-12-03 at 14:30 +0000, Daniele Varrazzo wrote:
> =Thank you for the report. Sorry for the stupid bug> (https://github.com/dvarrazzo/psycopg/commit/9a031db8b90488afb59e0d6c8995398c88b6bc41).Thanks a lot for fixing it so quickly. That's why I love Free
>
> To be released in 2.4.6 (which is really due now).
Software :)
Moreover: that's why I love Daniele and Federico :-)
Ciao.
Marco.
Marco.