Opened 5 hours ago

Closed 2 hours 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:1 by Shashank Kushwaha, 5 hours ago

Hi, I’d like to work on this issue. I’ll be submitting a patch soon.

Last edited 5 hours ago by Shashank Kushwaha (previous) (diff)

comment:2 by Shashank Kushwaha, 5 hours ago

Owner: set to Shashank Kushwaha
Status: newassigned

comment:3 by Shashank Kushwaha, 5 hours ago

Has patch: set

comment:4 by Shashank Kushwaha, 3 hours 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 Mariusz Felisiak, 2 hours ago

Resolution: wontfix
Status: assignedclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top