aio-libs / aiopg

aiopg is a library for accessing a PostgreSQL database from the asyncio
http://aiopg.readthedocs.io
BSD 2-Clause "Simplified" License
1.4k stars 160 forks source link

executing a query on a closed SAConnection throws a non-indicative exception #809

Closed brianmaissy closed 3 years ago

brianmaissy commented 3 years ago

If I create and then close an SAConnection and then call .execute() on it, it will raise the following exception:

AttributeError: 'NoneType' object has no attribute 'cursor'

It originates here: https://github.com/aio-libs/aiopg/blob/50b0822554706db0bf1fac3f376bebb579af3cef/aiopg/sa/connection.py#L85

Is it possible to check if the connection is closed before using it, and throwing a clearer exception?

Pliner commented 3 years ago

Hi @brianmaissy,

Surething. Could you submit a PR please?

Pliner commented 3 years ago

Fixed by #811