Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On Heroku, locale.getdefaultlocale() is returning (None, None), breaking Django createsuperuser – how to fix?

Trying to do a heroku python manage.py createsuperuser gave me an error that ended roughly:

File "/usr/local/www/site-python/lib/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

Entering a shell confirmed: locale.getdefaultlocale() is returning (None, None) on my Heroku Cedar stack. How do I set the locale such that python picks it up?

like image 836
gojomo Avatar asked Dec 04 '22 05:12

gojomo


1 Answers

To answer my own question: it turns out this can be fixed by the setting a heroku configuration variable, which results in an environment variable that python can pick up, which returns usable values from locale.getdefaultlocale().

In my case the heroku setting I used was:

heroku config:add LANG=en_US.UTF-8

(Of course other encoding and especially language values might make sense for others.)

It fixed the createsuperuser issue and so far so good on everything else. (Other reports suggest users doing a syncdb and choosing to create a superuser then have also hit this same error on some systems.)

Note that any such change triggers a restart of your instance(s).

like image 177
gojomo Avatar answered May 17 '23 16:05

gojomo