#16017: createsuperuser fails if Python can't detect default locale
-------------------------------------+-------------------------------------
     Reporter:  prestontimmons       |                    Owner:  ramiro
         Type:  Bug                  |                   Status:  new
    Component:  Core (Management     |                  Version:  1.4
  commands)                          |               Resolution:
     Severity:  Normal               |             Triage Stage:  Accepted
     Keywords:  dceu2011             |      Needs documentation:  0
    Has patch:  1                    |  Patch needs improvement:  0
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  1                    |
-------------------------------------+-------------------------------------
Changes (by bugs-django@…):

 * status:  closed => new
 * resolution:  fixed =>


Comment:

 Still an issue:

 {{{
 sandbox@reactor webpymail % rm -r webpymail.db; LC_ALL=C LANG=C
 PYTHONPATH=..:$PYTHONPATH python manage.py syncdb
 Creating tables ...
 Creating table auth_permission
 Creating table auth_group_permissions
 Creating table auth_group
 Creating table auth_user_user_permissions
 Creating table auth_user_groups
 Creating table auth_user
 Creating table django_content_type
 Creating table django_session
 Creating table django_admin_log
 Creating table mailapp_useridentity
 Creating table mailapp_userprofile
 Creating table mailapp_folderstoexpand
 Creating table mailapp_attachments
 Creating table address_book

 You just installed Django's auth system, which means you don't have any
 superusers defined.
 Would you like to create one now? (yes/no): yes
 Traceback (most recent call last):
   File "manage.py", line 37, in <module>
     execute_manager(settings)
   File "/home/sandbox/.local/lib/python2.7/site-
 packages/django/core/management/__init__.py", line 459, in execute_manager
     utility.execute()
   File "/home/sandbox/.local/lib/python2.7/site-
 packages/django/core/management/__init__.py", line 382, in execute
     self.fetch_command(subcommand).run_from_argv(self.argv)
   File "/home/sandbox/.local/lib/python2.7/site-
 packages/django/core/management/base.py", line 196, in run_from_argv
     self.execute(*args, **options.__dict__)
   File "/home/sandbox/.local/lib/python2.7/site-
 packages/django/core/management/base.py", line 232, in execute
     output = self.handle(*args, **options)
   File "/home/sandbox/.local/lib/python2.7/site-
 packages/django/core/management/base.py", line 371, in handle
     return self.handle_noargs(**options)
   File "/home/sandbox/.local/lib/python2.7/site-
 packages/django/core/management/commands/syncdb.py", line 110, in
 handle_noargs
     emit_post_sync_signal(created_models, verbosity, interactive, db)
   File "/home/sandbox/.local/lib/python2.7/site-
 packages/django/core/management/sql.py", line 189, in
 emit_post_sync_signal
     interactive=interactive, db=db)
   File "/home/sandbox/.local/lib/python2.7/site-
 packages/django/dispatch/dispatcher.py", line 172, in send
     response = receiver(signal=self, sender=sender, **named)
   File "/home/sandbox/.local/lib/python2.7/site-
 packages/django/contrib/auth/management/__init__.py", line 73, in
 create_superuser
     call_command("createsuperuser", interactive=True, database=db)
   File "/home/sandbox/.local/lib/python2.7/site-
 packages/django/core/management/__init__.py", line 150, in call_command
     return klass.execute(*args, **defaults)
   File "/home/sandbox/.local/lib/python2.7/site-
 packages/django/core/management/base.py", line 232, in execute
     output = self.handle(*args, **options)
   File "/home/sandbox/.local/lib/python2.7/site-
 packages/django/contrib/auth/management/commands/createsuperuser.py", line
 70, in handle
     default_username = get_default_username()
   File "/home/sandbox/.local/lib/python2.7/site-
 packages/django/contrib/auth/management/__init__.py", line 105, in
 get_default_username
     default_username = get_system_username()
   File "/home/sandbox/.local/lib/python2.7/site-
 packages/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
 }}}

 Note that TypeError is raised, which is not on the list of handled
 exceptions.

 Python 2.7.3

 Django==1.4.3


 > The discription of this ticket, describes the solution, not the problem.
 I'd like to see a usecase, before the solution goes in.

 The problem I see is that django produces an unhandled exception in a
 default configuration of FreeBSD (which does not set LANG environment
 variable).

 This problem can be split into two sub-problems:

 1. Django refuses to work in a default configuration of FreeBSD.

 2. When django refuses to work, it does not provide user-friendly
 information on what needs to be done to make it work.

 > I disagree. It is no error to have no LANG defined in a terminal
 session. It is documented that locale.getdefaultlocale() can return (None,
 None).
 >
 > It is a bug to pass it to decode() without checking. Possible friendly
 solution would be to say “we can’t work out your terminal character
 encoding, please enter your username”, but if it happens to be an ascii
 string that’s a bit silly, isn’t it?
 >
 > Please default to ‘ascii’ or ‘UTF-8’ and handle UnicodeDecodeError as
 already implemented.

 Agree with this.

 >  I tend to trust the Python core devs on checking this; if they can't
 figure out the default locale, who am I to assume I can do better?

 If you cannot figure out the default locale, and therefore are unable to
 determine how to interpret the username obtained by getuser(), why not
 take the except path and set the initial username to an empty string?
 Sounds like a better solution than preventing the user from being able to
 use django applications entirely.

 
https://code.djangoproject.com/attachment/ticket/16017/check_for_type_error.diff
 does fix the issue, although it is rather a hack. Instead the return value
 of getdefaultlocale should be checked before being used.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/16017#comment:49>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to