﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35942	createsuperuser management command crash on Python 3.13 when cannot be found in the OS.	Mariusz Felisiak	Tommy Allen	"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."	Bug	closed	contrib.auth	5.1	Release blocker	fixed		Mariusz Felisiak Jacob Walls	Ready for checkin	1	0	0	0	0	0
