Code

Opened 2 years ago

Last modified 12 days ago

#18192 new Bug

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

Reported by: jedie Owned by: nobody
Component: Internationalization Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
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"

Attachments (0)

Change History (9)

comment:1 follow-up: Changed 2 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 2 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 2 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 20 months ago by paulo.koch@…

This clearly needs a better error message.

comment:5 Changed 11 months 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 8 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 8 months ago by beck (previous) (diff)

comment:7 Changed 4 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 13 days 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 12 days 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as new
The owner will be changed from nobody to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.