Opened 3 hours ago
Closed 30 minutes ago
#37001 closed Bug (wontfix)
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 (5)
comment:2 by , 3 hours ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
comment:3 by , 3 hours ago
| Has patch: | set |
|---|
comment:4 by , 80 minutes 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!
comment:5 by , 30 minutes ago
| Resolution: | → wontfix |
|---|---|
| Status: | assigned → closed |
We are talking about management command used rarely by users. I see no value is raising an exception or adding a logger here. This is not something that will not be noticed when executing a command.
Hi, I’d like to work on this issue. I’ll submit a patch soon.