Code

Opened 2 years ago

Closed 2 years ago

#17185 closed Bug (duplicate)

[patch] manage.py createsuperuser fails when locale is not set

Reported by: nlsp Owned by: nobody
Component: contrib.auth Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

When locale(1) is like
LANG=
LC_CTYPE="C"
LC_COLLATE="C"
LC_TIME="C"
LC_NUMERIC="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_ALL=

then "./manage.py createsuperuser" results in a traceback ending

File "/usr/lib/py-dev/django-trunk/django/contrib/auth/management/__init__.py", line 85, in get_system_username
    return getpass.getuser().decode(locale.getdefaultlocale()[1])
TypeError: decode() argument 1 must be string, not None

Since get_system_username() tries to guard against restricted environments like being run in a chroot() environment chances are there is no sane LANG environment either — resulting in getdefaultlocale() returning (None, None).

Assuming ascii encoding is probably okay because UnicodeDecodeError is catched anyway. Calling decode() with ‘ignore’ or not is a matter of taste.

See attached patch.

Attachments (1)

get_username.patch (787 bytes) - added by nlsp 2 years ago.
patches get_system_username() to function correctly when locale is not set up

Download all attachments as: .zip

Change History (2)

Changed 2 years ago by nlsp

patches get_system_username() to function correctly when locale is not set up

comment:1 Changed 2 years ago by kmtracey

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #17022, #16017

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.