sqlalchemy_aio icon indicating copy to clipboard operation
sqlalchemy_aio copied to clipboard

execute() never returns if DB is empty

Open tvogt opened this issue 4 years ago • 2 comments

While testing, I found a curious behaviour:

result = await conn.execute(data.select().where(data.c.owner == ctx.author.id))

This works properly if there is data, both when data is found and when not found.

However, if the DB is not initialized, it will hang. It never returns, neither with a success nor with a failure.

tvogt avatar Feb 28 '20 19:02 tvogt

(using sqlite, btw.)

tvogt avatar Feb 28 '20 19:02 tvogt

Please provide an MCVE.

I tried variants of this and wasn't able to reproduce:

import asyncio
import os

from sqlalchemy_aio import ASYNCIO_STRATEGY

from sqlalchemy import Column, Integer, MetaData, Table, create_engine
from sqlalchemy.schema import CreateTable

meta = MetaData()
data = Table('data', meta, Column('owner', Integer))


async def main():
    try:
        os.unlink('test.db')
    except FileNotFoundError:
        pass

    engine = create_engine('sqlite:///test.db', strategy=ASYNCIO_STRATEGY)

    async with engine.connect() as conn:
        await conn.execute(CreateTable(data))
        result = await conn.execute(data.select().where(data.c.owner == 1))
        print(result)


if __name__ == '__main__':
    asyncio.run(main())

RazerM avatar Mar 06 '20 23:03 RazerM