Opened 3 years ago

Closed 13 months ago

#18192 closed Bug (fixed)

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

Reported by: jedie Owned by: claudep
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 follow-up: Changed 3 years ago by claudep

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 in reply to: ↑ 1 Changed 3 years ago by jedie

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 Changed 3 years ago by claudep

  • Resolution set to wontfix
  • Status changed from new to closed

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 Changed 3 years ago by paulo.koch@…

This clearly needs a better error message.

comment:5 Changed 2 years ago by timo

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 Changed 21 months ago by beck

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 21 months ago by beck (previous) (diff)

comment:7 Changed 18 months ago by fernandogrd@…

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 Changed 14 months ago by anonymous

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 Changed 14 months ago by anonymous

  • Needs documentation set
  • Resolution wontfix deleted
  • Status changed from closed to new

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 Changed 13 months ago by timo

  • Needs documentation unset
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

@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 Changed 13 months ago by claudep

  • Owner changed from nobody to claudep
  • Status changed from new to assigned

I'll see if we can improve things.

comment:12 Changed 13 months ago by timo

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

comment:13 Changed 13 months ago by Claude Paroz <claude@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In a5f6cbce07b5f3ab48d931e3fd1883c757fb9b45:

Refactored DjangoTranslation class

Also fixes #18192 and #21055.

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