Opened 13 years ago

Closed 13 years ago

#17022 closed Bug (duplicate)

createsuperuser / get_default_username fail on systems without default locale encoding

Reported by: Preston Holmes Owned by: nobody
Component: contrib.auth Version: dev
Severity: Release blocker Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

r16182 introduced a regression in the case of systems that, for whatever reason, don't provide a locale encoding.

For example on OS X Server 10.6:

>>> import locale
>>> locale.getdefaultlocale()
(None, None)

as documented for the locale module, None is a valid return value:

http://docs.python.org/library/locale.html#locale.getdefaultlocale

However, the decode function does not allow None and will raise a TypeError:

>>> get_default_username()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/private/tmp/foo/src/django/django/contrib/auth/management/__init__.py", line 105, in get_default_username
    default_username = get_system_username()
  File "/private/tmp/foo/src/django/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

the attach patch should fix this for most cases, since UTF8 is the best default

however, short of mocking locale.getdefaultlocale, I'm not sure how to test this.

Attachments (1)

get_system_username.diff (718 bytes ) - added by Preston Holmes 13 years ago.

Download all attachments as: .zip

Change History (2)

by Preston Holmes, 13 years ago

Attachment: get_system_username.diff added

comment:1 by Karen Tracey, 13 years ago

Resolution: duplicate
Status: newclosed

Already reported in #16017

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