FSX / momoko

Wraps (asynchronous) Psycopg2 for Tornado.
http://momoko.61924.nl/
Other
362 stars 73 forks source link

when using RealDictCursor, Pool.register_json error #154

Closed HunDunDM closed 5 years ago

HunDunDM commented 7 years ago

I guess the reason is: in momoko.connection.Connection._register will get oid, array_oid = 'json_oid', 'json_arr_oid' but we should get oid, array_oid = 114, 199

haizaar commented 6 years ago

Hi,

If still relevant, can you please post the full reproduction?

HunDunDM commented 6 years ago

still relevant, I now use

psycopg2.extras.register_default_json(globally=True)
psycopg2.extras.register_default_jsonb(globally=True)

instead of await pool.register_json()

reproduction (python==3.6.4, tornado==5.0, psycopg2-binary==2.7.4)

import momoko
import psycopg2.extras
from tornado.ioloop import IOLoop

async def main():
    dsn = 'dbname=xxxxxx user=xxxxxx password=xxxxx host=xxxx port=xxxx'
    pool = momoko.Pool(
        dsn=dsn,
        setsession=["SET TIME ZONE PRC"],
        cursor_factory=psycopg2.extras.RealDictCursor,  # delete this line, the problem does not exist
    )
    await pool.connect()
    await pool.register_json()
    # psycopg2.extras.register_default_json(globally=True)
    # psycopg2.extras.register_default_jsonb(globally=True)
    pool.close()

if __name__ == '__main__':
    ioloop = IOLoop.current()
    ioloop.run_sync(main)