Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#26046 closed Bug (fixed)

ugettext causes error when unrecognized language code in language cookie

Reported by: jenlu Owned by: Claude Paroz
Component: Internationalization Version: dev
Severity: Release blocker Keywords: i18n
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

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 language 'no' (norwegian).

I ended up migrating all users from 'no' to 'nb' (Norwegian Bokmal) and since this is a recognized language code then things work.

Still, seems a little hard to get server error under Django 1.9.1 just because a erroneous language code is set by mistake...

Attached trace info below:

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'

Change History (7)

comment:1 by Tim Graham, 8 years ago

Description: modified (diff)

comment:2 by Claude Paroz, 8 years ago

Owner: changed from nobody to Claude Paroz
Severity: NormalRelease blocker
Status: newassigned
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug
Version: 1.9master

This is a regression caused by cd3c042b0473e762b0e89bc69a9244c4a1fed66e

comment:3 by Claude Paroz, 8 years ago

Has patch: set

comment:4 by Tim Graham, 8 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Claude Paroz <claude@…>, 8 years ago

Resolution: fixed
Status: assignedclosed

In 632a9f21:

Fixed #26046 -- Fixed a crash with translations and Django-unknown language code

Thanks Jens Lundstrom for the report and Tim Graham for the review.

comment:6 by Claude Paroz <claude@…>, 8 years ago

In fe6d5689:

[1.9.x] Fixed #26046 -- Fixed a crash with translations and Django-unknown language code

Thanks Jens Lundstrom for the report and Tim Graham for the review.
Backport of 632a9f21bc from master.

comment:7 by Claude Paroz <claude@…>, 8 years ago

In 61437dd0:

[1.8.x] Fixed #26046 -- Fixed a crash with translations and Django-unknown language code

Thanks Jens Lundstrom for the report and Tim Graham for the review.
Backport of 632a9f21bc from master.

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