Problem with the default registration of the JSON adapter

Поиск
Список
Период
Сортировка
От Daniele Varrazzo
Тема Problem with the default registration of the JSON adapter
Дата
Msg-id 1374259266.26059.111.camel@risotto.smithersbet.com
обсуждение исходный текст
Ответы Re: Problem with the default registration of the JSON adapter
Re: Problem with the default registration of the JSON adapter
Список 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



В списке psycopg по дате отправления:

Предыдущее
От: Daniele Varrazzo
Дата:
Сообщение: Re: Error in a simple query (SOLVED)
Следующее
От: Christophe Pettus
Дата:
Сообщение: Re: Problem with the default registration of the JSON adapter