0

Currently attempting to upgrade Django 187 --> 191 but am running into an unexpected problem with translations in my template files. At first occurrence of a trans-tag in template I get the error below. Seems to me like ugettext is not defaulting back correctly when no mo/po file is found or match for this string (currently no translations files for no/norwegian in use so should just stick with existing name).

All translations have worked correctly for a long long time so this was unexpected...

Any ideas?

NoneType' object has no attribute 'get'
Request Method: GET
Request URL:    http://shootnscoreit.com/dashboard/
Django Version: 1.9.1
Exception Type: AttributeError
Exception Value:    
'NoneType' object has no attribute 'get'
Exception Location: /usr/local/lib/python2.7/gettext.py in ugettext, line 400

...

    usr/local/lib/python2.7/gettext.py in ugettext
    400.     tmsg = self._catalog.get(message, missing)

Local Vars

    Variable    Value
    message     u'Armoury'
    self        <DjangoTranslation lang:no>
    missing     <object object at 0x7f0e72c00740>

...

   File "/home/tss/webapps/shoot_django/lib/python2.7/django/templatetags/i18n.py", line 89, in render
     value = render_value_in_context(output, context)
   File "/home/tss/webapps/shoot_django/lib/python2.7/django/template/base.py", line 1022, in render_value_in_context
     value = force_text(value)
  File "/home/tss/webapps/shoot_django/lib/python2.7/django/utils/encoding.py", line 78, in force_text
     s = six.text_type(s)
   File "/home/tss/webapps/shoot_django/lib/python2.7/django/utils/functional.py", line 114, in __text_cast
    return func(*self.__args, **self.__kw)
   File "/home/tss/webapps/shoot_django/lib/python2.7/django/utils/translation/__init__.py", line 85, in ugettext
    return _trans.ugettext(message)
   File "/home/tss/webapps/shoot_django/lib/python2.7/django/utils/translation/trans_real.py", line 318, in ugettext
     return do_translate(message, 'ugettext')
   File "/home/tss/webapps/shoot_django/lib/python2.7/django/utils/translation/trans_real.py", line 298, in do_translate
    result = getattr(translation_object, translation_function)(eol_message)
   File "/usr/local/lib/python2.7/gettext.py", line 400, in ugettext
     tmsg = self._catalog.get(message, missing)
 AttributeError: 'NoneType' object has no attribute 'get'
Jens Lundstrom
  • 702
  • 8
  • 15
  • checked logs and have this issue wrt i18n: 2015-12-14 13:53:46,856 - py.warnings - WARNING - /home/tss/webapps/shoot_django/lib/python2.7/django/utils/translation/__init__.py:146: RemovedInDjango19Warning: The use of the language code 'zh-cn' is deprecated. Please use the 'zh-hans' translation instead. return _trans.activate(language) – Jens Lundstrom Jan 04 '16 at 13:19
  • been able to recreate this, seems when an unrecognized language code (in this case no = norwegian generic (can also be nn and nb - ny norsk and norsk bokmal)) this happens in django 191 but not 187... strange... – Jens Lundstrom Jan 06 '16 at 13:27
  • ended up migrating language cookie for all from 'no' ---> 'nb', this was only language code that was not existing in Django default languages. Seems Django 1.9.1 was more sensitive on this matter then 1.8.7 – Jens Lundstrom Jan 06 '16 at 14:16
  • I'm seeing this after upgrade from 1.9 to 1.9.1, the only related commit seems to be https://github.com/django/django/commit/f0a4ff2b118cbc3b7f9ac28a7d9e355288b546c0 – Michal Čihař Jan 07 '16 at 09:18

1 Answers1

0

This happens when you try to set language which is not listed in LANGAUGES settings. For me this was caused by invalid user preferences (which were probably valid at some point in past) and translation.activate just worked without any error.

This was caused by https://github.com/django/django/commit/f0a4ff2b118cbc3b7f9ac28a7d9e355288b546c0

PS: I've reported this as I believe this is regression which should not happen: https://code.djangoproject.com/ticket/26050

PS2: That just showed my inability to search in existing reports as it's duplicate of https://code.djangoproject.com/ticket/26046, which has been already fixed.

Michal Čihař
  • 9,799
  • 6
  • 49
  • 87