This project is archived and is in readonly mode.
row_to_json data gets interpreted
-
Federico Di Gregorio
I have to agree. IMHO, the json adapter should exist but its registration should not be automatic.
-
Daniele Varrazzo
Mmm, i think you are right, the choice of adapting automatically json is questionable.
Eric, while we decide how to fix the problem you can disable the automatic adaptation using:
import psycopg2.extensions as ext ext.string_types.pop(ext.JSON.values[0], None) ext.string_types.pop(ext.JSONARRAY.values[0], None)It's enough to do it only once and is idempotent anyway. If you guard it with an
if hasattr(ext, 'JSON')it would work with any psycopg release. -
Daniele Varrazzo
I've written to the mailing list my ideas about the issue. Feel free to take part to the discussion.
The automatic cast of json was introduced in a major release (2.5): although the choice can be questioned (not that anybody did) it was done in a legitimate moment. Dropping automatic casting in 2.5.x would be a bad reaction; the right moment to think about a different behaviour is for 2.6.
You have plenty of options to work around the issue:
- use psycopg < 2.4.x, which is still being maintained
(
pip install "psycopg2<2.5"will give you the most up-to-date) - cast your json as text in the query
- use the above snippet to unregister the json typecaster.
Sorry for the inconvenience.
- use psycopg < 2.4.x, which is still being maintained
(
-
Daniele Varrazzo
- State changed from new to resolved
After a chat on the ML, the idea is to leave the json adapter as it is.
Easy workarounds are to cast json to text and to register the text/unicode adapter on the JSON oid.