Opened 12 years ago

Closed 10 years ago

#18192 closed Bug (fixed)

If translation not exist: 'NoneType' object has no attribute '_info'

Reported by: jedie Owned by: Claude Paroz
Component: Internationalization Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

I get this error:

Traceback (most recent call last):
  File "./manage.py", line 91, in <module>
    execute_from_command_line()
  File ".../env/src/django/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File ".../env/src/django/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File ".../env/src/django/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File ".../env/src/django/django/core/management/base.py", line 251, in execute
    translation.activate(saved_lang)
  File ".../env/src/django/django/utils/translation/__init__.py", line 105, in activate
    return _trans.activate(language)
  File ".../env/src/django/django/utils/translation/trans_real.py", line 194, in activate
    _active.value = translation(language)
  File ".../env/src/django/django/utils/translation/trans_real.py", line 183, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
  File ".../env/src/django/django/utils/translation/trans_real.py", line 147, in _fetch
    res._info = res._info.copy()
AttributeError: 'NoneType' object has no attribute '_info'

django/utils/translation/trans_real.py doesn't handle the error if translation file doesn't found. e.g.:

IOError: [Errno 2] No translation file found for domain: 'django'

This would fix it:

django/utils/translation/trans_real.py

@@ -138,6 +138,12 @@ def translation(language):
 
         res = _translation(globalpath)
 
+        if res is None:
+            return gettext_module.NullTranslations()
+
         # We want to ensure that, for example,  "en-gb" and "en-us" don't share
         # the same translation object (thus, merging en-us with a local update
         # doesn't affect en-gb), even though they will both use the core "en"

Change History (13)

comment:1 by Claude Paroz, 12 years ago

Could you please tell us how you were able to produce this error? What is the LANGUAGE_CODE value?

in reply to:  1 comment:2 by jedie, 12 years ago

Replying to claudep:

Could you please tell us how you were able to produce this error? What is the LANGUAGE_CODE value?

I figured out that all *.mo files are deleted :( Don't know why, but that results in the error.

comment:3 by Claude Paroz, 12 years ago

Resolution: wontfix
Status: newclosed

OK, now I understand the error. I don't think we should do anything here. If Django files are deleted, the user has to bear the consequences, sorry!

comment:4 by paulo.koch@…, 12 years ago

This clearly needs a better error message.

comment:5 by Tim Graham, 11 years ago

Here's a pull request, opened 2 months ago, even though the ticket was marked as won't fix: https://github.com/django/django/pull/955.

It needs discussion on the django-developers mailing list I suppose.

comment:6 by Doug Beck, 11 years ago

Discovered this ticket when trying to answer someone else with the same issue: https://groups.google.com/forum/#!msg/django-users/tc0asF6iFBo/u3cBN0SlUl0J

Think this ticket should be reopened, an IOError should be bubbled up to the user.

The bit of source code that causes this issue also causes another nuance bug: ticket:21055

Opened a pull to test and patch both issues: https://github.com/django/django/pull/1562

Last edited 11 years ago by Doug Beck (previous) (diff)

comment:7 by fernandogrd@…, 10 years ago

I got bit by this today, the language code was: zh-Hant, and is something I don't have in LANGUAGES settings.

A interesting point is that it only happened in my production instances (Centos 6), in my Arch installation, activate falls back ok to default language (en-us).

comment:8 by anonymous, 10 years ago

This error occurs intermittently if you try to add a custom language in the settings module.

E.g. I have to support two languages: zh-tw and zh-hk.
zh-tw works out of the box but I have made changes to django settings bundle for zh-hk.

Now, if I start my server and send a zh-hk request, it works.
But if I start my server, send a zh-tw request and then send a zh-hk request, I get this error.

Please look into this.

comment:9 by anonymous, 10 years ago

Needs documentation: set
Resolution: wontfix
Status: closednew

I'm also seeing this with a custom language in the LANGUAGES setting. Language codes already in global_settings.py seem to work fine.

I added zh-hk into LANGUAGES with the po and mo files into locale/zh_HK

I'm seeing the same behaviour as:

Now, if I start my server and send a zh-hk request, it works.
But if I start my server, send a zh-tw request and then send a zh-hk request, I get this error.

Is it the case we can only use the same languages as defined in Django's global_settings.py? If so, this badly needs documenting! If not, then there is a bug here.

comment:10 by Tim Graham, 10 years ago

Needs documentation: unset
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

@claudep, from your previous comment, I guess you understand what is going on here. Maybe we could at least add a better error message?

comment:11 by Claude Paroz, 10 years ago

Owner: changed from nobody to Claude Paroz
Status: newassigned

I'll see if we can improve things.

comment:12 by Tim Graham, 10 years ago

Is #21055 a duplicate? It has a patch and the traceback is similar.

comment:13 by Claude Paroz <claude@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In a5f6cbce07b5f3ab48d931e3fd1883c757fb9b45:

Refactored DjangoTranslation class

Also fixes #18192 and #21055.

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