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: 1374259266.26059.111.camel@risotto.smithersbet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
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?

[1] http://psycopg.lighthouseapp.com/projects/62710-psycopg/tickets/172

--
Daniele

Responses

Browse psycopg by date

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