Opened 2 hours ago
Last modified 87 seconds ago
#37001 assigned Bug
get_system_username silently returns empty string on failure
| Reported by: | Shashank Kushwaha | Owned by: | Shashank Kushwaha |
|---|---|---|---|
| Component: | Utilities | Version: | 6.0 |
| Severity: | Normal | Keywords: | error-handling username logging |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
The function get_system_username() silently returns an empty string when exceptions occur (ImportError, KeyError, OSError).
This may make debugging difficult and can lead to unexpected downstream behavior where an empty username is treated as valid.
### Expected behavior
It might be helpful to at least log this situation (e.g., at debug level) to improve visibility.
### Context
This behavior occurs in environments where getpass.getuser() fails (e.g., restricted systems or missing passwd entries).
Change History (4)
comment:2 by , 2 hours ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
comment:3 by , 98 minutes ago
| Has patch: | set |
|---|
comment:4 by , 87 seconds ago
Hi, I have submitted a PR to address this issue.
GitHub PR: https://github.com/django/django/pull/20982
This adds debug logging when get_system_username() fails, improving visibility without changing behavior.
Feedback is welcome. Thanks!
Hi, I’d like to work on this issue. I’ll be submitting a patch soon.