aio-libs / aio-libs/aiomysql

Importing fails with OSError from `getpass.getuser` on Python 3.13+

オープン
#1,053 コメント 0 件 リアクション 2 件 担当者 0 名 GitHub で見る
bug
主要言語
Python
スター
1.9k
フォーク
272
PR マージ指標
30日以内にマージされた PR はありません

説明

### Describe the bug

As of Python 3.13, `getpass.getuser` [now raises OSError](https://bugs.python.org/issue?@action=redirect&bpo=32731) on any failures instead of KeyError. This means that [this line](https://github.com/aio-libs/aiomysql/blob/db2f54eaf064c9cddfc84fc5dd8c9720170dc266/aiomysql/connection.py#L43) doesn't work anymore, and the library crashes on import.

PyMySQL fixed this issue in this commit: https://github.com/PyMySQL/PyMySQL/commit/a1ac8239c8bf79e7f1a17347b10d6e184221f9c1

### To Reproduce

1. Import aiomysql inside a Docker container with Python 3.13+ with the UID set to something without a username.
2. Observe crash.

### Expected behavior

It does not crash.

### Logs/tracebacks

```python-traceback
Traceback (most recent call last):
File "/usr/local/lib/python3.13/getpass.py", line 173, in getuser
return pwd.getpwuid(os.getuid())[0]
~~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'getpwuid(): uid not found: 8459'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "/app/lib/python3.13/site-packages/package/__main__.py", line 1, in
from package import main
File "/app/lib/python3.13/site-packages/package/esc_dl.py", line 17, in
import aiomysql
File "/app/lib/python3.13/site-packages/aiomysql/__init__.py", line 32, in
from .connection import Connection, connect
File "/app/lib/python3.13/site-packages/aiomysql/connection.py", line 42, in
DEFAULT_USER = getpass.getuser()
File "/usr/local/lib/python3.13/getpass.py", line 175, in getuser
raise OSError('No username set in the environment') from e
OSError: No username set in the environment
```

### Python Version

```console
$ python --version
Python 3.13.9
```

### aiomysql Version

```console
$ python -m pip show aiomysql
Name: aiomysql
Version: 0.3.2
Location: /package/.venv/lib/python3.13/site-packages
Requires: pymysql
Required-by: ...
```

### PyMySQL Version

```console
$ python -m pip show PyMySQL
Name: pymysql
Version: 1.1.2
Location: /package/.venv/lib/python3.13/site-packages
Requires:
Required-by: aiomysql
```

### SQLAlchemy Version

```console
$ python -m pip show sqlalchemy
N/A
```

### OS

Linux 6.8.0-84-generic #84-Ubuntu SMP PREEMPT_DYNAMIC Fri Sep 5 22:36:38 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

### Database type and version

```console
SELECT VERSION();
N/A
```

### Additional context

_No response_

### Code of Conduct

- [x] I agree to follow the aio-libs Code of Conduct

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。