Opened 7 years ago

Closed 5 years ago

Last modified 5 years ago

#7077 closed (fixed)

Provide a fallback for pwd

Reported by: damien_szczyt Owned by: nobody
Component: Contrib apps Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:

Description

I've created a UNIX user in a mysql database, but my settings doesn't allow the user to know its username via getpwuid.
This is a small patch to set the default username as 'admin' if getpwuid fails.

Attachments (1)

set_default_user_as_admin_if_getpwuid_fails.patch (571 bytes) - added by damien_szczyt 7 years ago.

Download all attachments as: .zip

Change History (5)

Changed 7 years ago by damien_szczyt

comment:1 Changed 7 years ago by telenieko

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from Creating user when syncdb doesn't work if getpwuid is not available to Provide a fallback for pwd

Altought I don't see why would one prevent getpwuid to work, why don't you first try to read the $USER variable?
That would be a better fallback, even:

default_username = os.environ.get('USER', 'admin')

would do the job.

Anyway, this has been deprecated, you should patch django/contrib/auth/management/commands/createsuperuser.py now.

comment:2 Changed 7 years ago by mtredinnick

  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

Regarding this patch:

  1. Bare excepts are bad. We should catch the right exception type explicitly.
  2. If retrieving the default user doesn't work, it should be set to the empty string, just like if the pwd module cannot be imported. No reason to introduce any other default.
  3. As telenieko mentioned, when the patch is updated to accommodate these changes, the relevant code is now in django/contrib/auth/management/commands/createsuperuser.py

comment:3 Changed 5 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

(In [14607]) Fixed #7077 and #7431 -- Use getpass.getuser instead of pwd.getpwuid to determine the current system user's username in the createsuperuser management command to enable the feature on Windows. getpass.getuser automatically falls back to the previous method.

comment:4 Changed 5 years ago by jezdez

(In [14608]) [1.2.X] Fixed #7077 and #7431 -- Use getpass.getuser instead of pwd.getpwuid to determine the current system user's username in the createsuperuser management command to enable the feature on Windows. getpass.getuser automatically falls back to the previous method.

Backport from trunk (r14607).

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