aio-libs / aio-libs/aiomysql

aiomysql.sa example fails with "TypeError: 'ResultProxy' object is not iterable" since 0.0.15

Aberta
#300 2 comentários 9 reações 0 responsáveis Ver no GitHub
bug sqlalchemy
Linguagem predominante
Python
Estrelas
1.9k
Forks
272
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

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.

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.