aiomysql.sa example fails with "TypeError: 'ResultProxy' object is not iterable" since 0.0.15
- 主要语言
- Python
- 星标
- 1.9k
- 派生
- 272
- PR 合并指标
- 30 天内没有已合并 PR
描述
Hi!
I was trying to run the example from http://aiomysql.readthedocs.io/en/latest/sa.html :
```python
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)
in ()
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):
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: https://github.com/aio-libs/aiomysql/commit/83252b36e3476779d98059119dec3c4140a7befe so I believe that the example should be brought in line with current code.
贡献指南
评估
这个 Issue 还没有评估数据。