Opened 2 hours ago
Last modified 2 hours ago
#35942 assigned Bug
createsuperuser management command crash on Python 3.13 when cannot be found in the OS.
Reported by: | Mariusz Felisiak | Owned by: | Tommy Allen |
---|---|---|---|
Component: | contrib.auth | Version: | 5.1 |
Severity: | Release blocker | Keywords: | |
Cc: | Mariusz Felisiak, Jacob Walls | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | yes |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The createsuperuser
management command raises OSError
when a username isn't found in the system while using Python 3.13.
getpass.getuser()
in Python 3.13 catches ImportError
and KeyError
the same way Django does, but raises OSError
instead: https://github.com/python/cpython/commit/99a73c3465a45fe57cac01a917fc50e0743b5964
# Reproduction steps
Run bash in a python:3.13 docker container to mount a directory owned by the local user to get a writable directory:
docker run --rm -it -u 1000:1000 -e HOME=/home/user -v $PWD:/home/user python:3.13 bash
Install Django:
pip install --user django
Create a project and run migration:
mkdir -p ~/djtest ~/.local/bin/django-admin startproject djtest /home/user/djtest ~/djtest/manage.py migrate
Create superuser:
~/djtest/manage.py createsuperuser
Exception output:
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: 1000' The above exception was the direct cause of the following exception: ... 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
Reported originally by tweekmonster.
PR