Opened 4 years ago

Closed 3 years ago

#17022 closed Bug (duplicate)

createsuperuser / get_default_username fail on systems without default locale encoding

Reported by: ptone Owned by: nobody
Component: contrib.auth Version: master
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 ptone 4 years ago.

Download all attachments as: .zip

Change History (2)

Changed 4 years ago by ptone

comment:1 Changed 3 years ago by kmtracey

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

Already reported in #16017

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