#7077 closed (fixed)
Provide a fallback for pwd
Reported by: | damien_szczyt | Owned by: | nobody |
---|---|---|---|
Component: | Contrib apps | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
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)
Change History (5)
by , 17 years ago
Attachment: | set_default_user_as_admin_if_getpwuid_fails.patch added |
---|
comment:1 by , 16 years ago
Summary: | Creating user when syncdb doesn't work if getpwuid is not available → Provide a fallback for pwd |
---|
comment:2 by , 16 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
Regarding this patch:
- Bare excepts are bad. We should catch the right exception type explicitly.
- 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. - 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 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:4 by , 14 years ago
(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).
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.