You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When intializing a new connection with cursor_factory=psycopg2.extras.RealDictCursor on a databse with hstore extension on, you get an error as follows. This is due to a dict being returned as result and not list.
Traceback (most recent call last):
File "wsclient.py", line 134, in
loop.run_until_complete(db.init_db())
File "/usr/lib/python3.5/asyncio/base_events.py", line 337, in run_until_complete
return future.result()
File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
raise self._exception
File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
result = coro.send(None)
File "/home/bernhardt/git_work/qs_switch/QS_Workflow/client/async_quantdb.py", line 25, in init_db
cursor_factory=psycopg2.extras.RealDictCursor)
File "/home/bernhardt/git_work/qs_switch/QS_Workflow/pyenv/lib/python3.5/site-packages/aiopg/utils.py", line 57, in await
resp = yield from self._coro
File "/home/bernhardt/git_work/qs_switch/QS_Workflow/pyenv/lib/python3.5/site-packages/aiopg/pool.py", line 45, in _create_pool
yield from pool._fill_free_pool(False)
File "/home/bernhardt/git_work/qs_switch/QS_Workflow/pyenv/lib/python3.5/site-packages/aiopg/pool.py", line 188, in _fill_free_pool
**self._conn_kwargs)
File "/home/bernhardt/git_work/qs_switch/QS_Workflow/pyenv/lib/python3.5/site-packages/aiopg/utils.py", line 52, in iter
resp = yield from self._coro
File "/home/bernhardt/git_work/qs_switch/QS_Workflow/pyenv/lib/python3.5/site-packages/aiopg/connection.py", line 78, in _connect
oids = yield from _enable_hstore(conn)
File "/home/bernhardt/git_work/qs_switch/QS_Workflow/pyenv/lib/python3.5/site-packages/aiopg/connection.py", line 37, in _enable_hstore
rv0.append(oids[0])
KeyError: 0
How to reproduce:
install
sudo apt-get install postgresql-contrib
create hstore extension on database
CREATE EXTENSION hstore;
create connection to datbase using aiopg, we created a pool, but as it calls connect function inside normal conection should fail aswell self._pool = await aiopg.create_pool(host=self.settings.DATABASE_HOST, database=self.settings.DATABASE_NAME, user=self.settings.DATABASE_USER, password=self.settings.DATABASE_PASS, port=self.settings.DATABASE_PORT, cursor_factory=psycopg2.extras.RealDictCursor)
Suggested solution:
Change "def _enable_hstore(conn):" in aiopg.connection
from
@asyncio.coroutine
def _enable_hstore(conn):
cur = yield from conn.cursor()
yield from cur.execute("""\
SELECT t.oid, typarray
FROM pg_type t JOIN pg_namespace ns
ON typnamespace = ns.oid
WHERE typname = 'hstore';
""")
rv0, rv1 = [], []
for oids in (yield from cur.fetchall()):
rv0.append(oids[0])
rv1.append(oids[1])
cur.close()
return tuple(rv0), tuple(rv1)
To
@asyncio.coroutine
def _enable_hstore(conn):
cur = yield from conn.cursor()
yield from cur.execute("""\
SELECT t.oid, typarray
FROM pg_type t JOIN pg_namespace ns
ON typnamespace = ns.oid
WHERE typname = 'hstore';
""")
rv0, rv1 = [], []
for oids in (yield from cur.fetchall()):
if type(oids) is list:
rv0.append(oids[0])
rv1.append(oids[1])
else:
rv0.append(oids['oid'])
rv1.append(oids['typarray'])
cur.close()
return tuple(rv0), tuple(rv1)
Regards
The text was updated successfully, but these errors were encountered:
This is my proposed solution for issue aio-libs#189.
It sesolves the problem where the query result is returned as a dict and not a list due to the cursor_factory being a RelDictRow
Hi
When intializing a new connection with cursor_factory=psycopg2.extras.RealDictCursor on a databse with hstore extension on, you get an error as follows. This is due to a dict being returned as result and not list.
How to reproduce:
install
create connection to datbase using aiopg, we created a pool, but as it calls connect function inside normal conection should fail aswell
self._pool = await aiopg.create_pool(host=self.settings.DATABASE_HOST, database=self.settings.DATABASE_NAME, user=self.settings.DATABASE_USER, password=self.settings.DATABASE_PASS, port=self.settings.DATABASE_PORT, cursor_factory=psycopg2.extras.RealDictCursor)
Suggested solution:
Change "def _enable_hstore(conn):" in aiopg.connection
from
To
Regards
The text was updated successfully, but these errors were encountered: