Open
Description
Hi!
I was trying to run the example from http://aiomysql.readthedocs.io/en/latest/sa.html :
import asyncio
import sqlalchemy as sa
from aiomysql.sa import create_engine
metadata = sa.MetaData()
tbl = sa.Table('tbl', metadata,
sa.Column('id', sa.Integer, primary_key=True),
sa.Column('val', sa.String(255)))
@asyncio.coroutine
def go():
engine = yield from create_engine(user='root',
db='test_pymysql',
host='127.0.0.1',
password='')
with (yield from engine) as conn:
yield from conn.execute(tbl.insert().values(val='abc'))
res = yield from conn.execute(tbl.select())
for row in res:
print(row.id, row.val)
asyncio.get_event_loop().run_until_complete(go())
and got the following:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-2-4a46c1f5df04> in <module>()
26 print(row.id, row.val)
27
---> 28 asyncio.get_event_loop().run_until_complete(go())
~/miniconda3/lib/python3.6/asyncio/base_events.py in run_until_complete(self, future)
466 raise RuntimeError('Event loop stopped before Future completed.')
467
--> 468 return future.result()
469
470 def stop(self):
<ipython-input-2-4a46c1f5df04> in go()
23
24 res = yield from conn.execute(tbl.select())
---> 25 for row in res:
26 print(row.id, row.val)
27
TypeError: 'ResultProxy' object is not iterable
replacing for row in res:
with something like
for row in (yield from res.fetchall()):
fixes the issue. A little exploration revealed that this error comes since 0.0.15 release and probably since this commit: 83252b3 so I believe that the example should be brought in line with current code.
Activity