Skip site navigation (1) Skip section navigation (2)

Problem with the default registration of the JSON adapter

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: psycopg(at)postgresql(dot)org
Subject: Problem with the default registration of the JSON adapter
Date: 2013-07-19 18:41:06
Message-ID: (view raw, whole thread or download thread mbox)
Lists: psycopg
Hello list,

ticket #172 [1] suggests I have been too eager with JSON and Postgres
9.2. The ticket is from an user who just wants to read the json from the
database and forward it to the web clients, so a json -> python
conversion would be just a waste of time. Psycopg 2.5 instead registers
the json adapter on the PG 9.2 oids automatically.

If anybody else finds the same problem and wants to receive json as text
in 9.2 too, the interim solution with psycopg 2.5 and 2.5.1 is the
following snippet:

        import psycopg2.extensions as ext
        if hasattr(ext, 'JSON'):
            ext.string_types.pop(ext.JSON.values[0], None)
            ext.string_types.pop(ext.JSONARRAY.values[0], None)

Another solution would be of course to cast the result to text instead.

What I would do is to introduce in the next release an unregister_json()
function doing roughly (but less roughly) what this snippet does.

I've taken in consideration the idea of dropping the automatic
registration of the json adapter after giving a few months of warning,
but thinking about that more coolly I think it would be a bad reaction.
The feature was legitimately added on a major release (2.5) and if
somebody finds it broken he can still install the last 2.4 available
(pip install "psycopg2<2.5"). The right moment to think about a
different behaviour (e.g. require register_json() to be called) is the
next major release.

Comments? Better ideas?




psycopg by date

Next:From: Christophe PettusDate: 2013-07-19 19:02:59
Subject: Re: Problem with the default registration of the JSON adapter
Previous:From: Daniele VarrazzoDate: 2013-06-25 09:55:09
Subject: Re: Error in a simple query (SOLVED)

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group