connection.close() returns None when called from async function - await fails
- Linguagem predominante
- Python
- Estrelas
- 1.9k
- Forks
- 272
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
### Describe the bug
see code to reproduce -
1) define async function
2) call connection = await aiomysql.connect(...)
3) execute some operation (SELECT 1)
4) call await connection.close()
5) app crashed
### To Reproduce
Execute attached python script
### Expected behavior
connection.close() should be returning a waitable object for await and not None
### Logs/tracebacks
```python-traceback
python test-aiomysql-close
2025-07-31 10:53:50,009 INFO : Attempting to connect to maria:3306...
2025-07-31 10:53:50,017 INFO : Successfully connected.
2025-07-31 10:53:50,018 INFO : Dummy query executed successfully.
2025-07-31 10:53:50,018 INFO : Type of conn.close() result (before await):
2025-07-31 10:53:50,018 INFO : Value of conn.close() result (before await): None
2025-07-31 10:53:50,018 INFO : Attempting to await conn.close()...
2025-07-31 10:53:50,018 ERROR : An error occurred: object NoneType can't be used in 'await' expression
Traceback (most recent call last):
File "/home/phil/temp/test-aiomysql-close", line 42, in test_close_behavior
await close_awaitable
TypeError: object NoneType can't be used in 'await' expression
```
### Python Version
```console
$ python --version
Python 3.12.3
```
### aiomysql Version
```console
$ python -m pip show aiomysql
Name: aiomysql
Version: 0.2.0
Summary: MySQL driver for asyncio.
Home-page: https://github.com/aio-libs/aiomysql
Author: Nikolay Novik
Author-email: nickolainovik@gmail.com
License: MIT
Location: /home/phil/dev/archiver/venv/lib/python3.12/site-packages
Requires: PyMySQL
Required-by: async-sqlalchemy
```
### PyMySQL Version
```console
$ python -m pip show PyMySQL
Name: PyMySQL
Version: 1.1.1
Summary: Pure Python MySQL Driver
Home-page:
Author:
Author-email: Inada Naoki , Yutaka Matsubara
License: MIT License
Location: /home/phil/dev/archiver/venv/lib/python3.12/site-packages
Requires:
Required-by: aiomysql
```
### SQLAlchemy Version
```console
$ python -m pip show sqlalchemy
Name: SQLAlchemy
Version: 2.0.40
Summary: Database Abstraction Library
Home-page: https://www.sqlalchemy.org
Author: Mike Bayer
Author-email: mike_mp@zzzcomputing.com
License: MIT
Location: /home/phil/dev/archiver/venv/lib/python3.12/site-packages
Requires: greenlet, typing-extensions
Required-by: async-sqlalchemy
```
### OS
cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.2 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.2 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo
### Database type and version
```console
SELECT VERSION();
'10.11.11-MariaDB-0ubuntu0.24.04.2'
```
### Additional context
Add code to application to ensure the db is created before sqlalchemy creates tables
### Code of Conduct
- [x] I agree to follow the aio-libs Code of Conduct
Guia de contribuição
Avaliação
Esta issue ainda não foi avaliada.