Edgewall Software

Opened 11 years ago

Closed 10 years ago

Last modified 3 years ago

#11345 closed defect (fixed)

AttributeError: NullTranslationsBabel instance has no attribute 'isactive' with Babel 1.3 — at Version 2

Reported by: Jun Omae Owned by: Jun Omae
Priority: normal Milestone: 0.12.6
Component: i18n Version: 1.0.1
Severity: normal Keywords: babel10
Cc: Branch:
Release Notes:

Fix AttributeError: NullTranslationsBabel instance has no attribute 'isactive' with Babel 1.0+

API Changes:
Internal Changes:

Description

Reproduced accessing /about or /prefs/language page if installed Trac 1.0.1 and Babel 1.3 with no compiled catalogs. 0.12-stable has the same issue.

Traceback (most recent call last):
  File "/home/jun66j5/src/trac/edgewall/git/trac/web/main.py", line 497, in _dispatch_request
    dispatcher.dispatch(req)
  File "/home/jun66j5/src/trac/edgewall/git/trac/web/main.py", line 233, in dispatch
    content_type)
  File "/home/jun66j5/src/trac/edgewall/git/trac/web/chrome.py", line 976, in render_template
    data = self.populate_data(req, data)
  File "/home/jun66j5/src/trac/edgewall/git/trac/web/chrome.py", line 837, in populate_data
    'footer': Markup(footer and translation.gettext(footer))
  File "/home/jun66j5/src/trac/edgewall/git/trac/util/translation.py", line 195, in gettext
    if not self.isactive:
  File "/home/jun66j5/src/trac/edgewall/git/trac/util/translation.py", line 190, in __getattr__
    return getattr(self.active, name)
AttributeError: NullTranslationsBabel instance has no attribute 'isactive'

The issue is Translations.add() raises AttributeError: 'NullTranslations' object has no attribute 'add'.

After modified def isactive(self) with the following;

  • trac/util/translation.py

    diff --git a/trac/util/translation.py b/trac/util/translation.py
    index cb9d5db..5e7c0e4 100644
    a b try:  
    175175
    176176        @property
    177177        def isactive(self):
    178             if self._current.args is not None:
    179                 get_locale, env_path = self._current.args
    180                 self._current.args = None
    181                 self.activate(get_locale(), env_path)
    182             # FIXME: The following always returns True: either a translation is
    183             # active, or activation has failed.
    184             return self._current.translations is not None \
    185                    or self._activate_failed
     178            try:
     179                if self._current.args is not None:
     180                    get_locale, env_path = self._current.args
     181                    self._current.args = None
     182                    self.activate(get_locale(), env_path)
     183                # FIXME: The following always returns True: either a translation is
     184                # active, or activation has failed.
     185                return self._current.translations is not None \
     186                       or self._activate_failed
     187            except AttributeError, e:
     188                import sys
     189                exc_info = sys.exc_info()
     190                raise Exception, unicode(e), exc_info[2]
    186191
    187192        # Delegated methods
    188193

We can retrieve the following traceback.

2013-10-22 23:13:50,205 Trac[main] ERROR: Internal Server Error:
Traceback (most recent call last):
  File "/home/jun66j5/src/trac/edgewall/git/trac/web/main.py", line 497, in _dispatch_request
    dispatcher.dispatch(req)
  File "/home/jun66j5/src/trac/edgewall/git/trac/web/main.py", line 233, in dispatch
    content_type)
  File "/home/jun66j5/src/trac/edgewall/git/trac/web/chrome.py", line 976, in render_template
    data = self.populate_data(req, data)
  File "/home/jun66j5/src/trac/edgewall/git/trac/web/chrome.py", line 837, in populate_data
    'footer': Markup(footer and translation.gettext(footer))
  File "/home/jun66j5/src/trac/edgewall/git/trac/util/translation.py", line 199, in gettext
    if not self.isactive:
  File "/home/jun66j5/src/trac/edgewall/git/trac/util/translation.py", line 182, in isactive
    self.activate(get_locale(), env_path)
  File "/home/jun66j5/src/trac/edgewall/git/trac/util/translation.py", line 152, in activate
    t.add(Translations.load(locale_dir, locale or 'en_US',
Exception: 'NullTranslations' object has no attribute 'add'

But, if 1.0.2dev (r12205), reproduced only if Accept-Language header is missing or unsupported locale and 2 plugins with catalogs are installed.

Traceback (most recent call last):
  File "/home/jun66j5/src/trac/edgewall/git/trac/web/main.py", line 497, in _dispatch_request
    dispatcher.dispatch(req)
  File "/home/jun66j5/src/trac/edgewall/git/trac/web/main.py", line 233, in dispatch
    content_type)
  File "/home/jun66j5/src/trac/edgewall/git/trac/web/chrome.py", line 990, in render_template
    data = self.populate_data(req, data)
  File "/home/jun66j5/src/trac/edgewall/git/trac/web/chrome.py", line 851, in populate_data
    'footer': Markup(footer and translation.gettext(footer))
  File "/home/jun66j5/src/trac/edgewall/git/trac/util/translation.py", line 200, in gettext
    if not self.isactive:
  File "/home/jun66j5/src/trac/edgewall/git/trac/util/translation.py", line 182, in isactive
    self.activate(get_locale(), env_path)
  File "/home/jun66j5/src/trac/edgewall/git/trac/util/translation.py", line 159, in activate
    t.add(Translations.load(dirname, locale, domain))
  File "/home/jun66j5/venv/py26-babel1/lib/python2.6/site-packages/babel/support.py", line 571, in add
    existing.merge(translations)
Exception: 'NullTranslations' object has no attribute 'merge'

Change History (2)

comment:1 by Jun Omae, 10 years ago

Milestone: next-stable-1.0.x0.12.6
Owner: set to Jun Omae
Status: newassigned

0.12-stable has the same issue with Babel 1.0+.

Proposed fix for 0.12.6 can be found in log:jomae.git:ticket11345_0.12.6dev, for 1.0.2 in log:jomae.git:ticket11345.

comment:2 by Jun Omae, 10 years ago

Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Committed in [12274] and merged in [12275,12276].

Note: See TracTickets for help on using tickets.