Edgewall Software
Modify

Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#11345 closed defect (fixed)

AttributeError: NullTranslationsBabel instance has no attribute 'isactive' with Babel 1.3

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:

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'

Attachments (0)

Change History (6)

comment:1 Changed 5 years ago by Jun Omae

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 Changed 5 years ago by Jun Omae

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

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

comment:3 Changed 5 years ago by anonymous

Just tested out Babel 1.3 and stumbled on this bug.

Now I can only hope that trac 1.0.2 will be released some day :-(

comment:4 in reply to:  3 Changed 5 years ago by Jun Omae

Replying to anonymous:

Just tested out Babel 1.3 and stumbled on this bug.

I recommend using Babel 0.9.6 for Trac.

comment:5 Changed 4 years ago by Dirk Stöcker

I have babel 1.3 as well and we got following report: https://josm.openstreetmap.de/ticket/10521 Is this related? It happens when trying to attach something to a wiki page. If yes, I probably need to open a bug for genshi?

comment:6 in reply to:  5 Changed 4 years ago by Jun Omae

Replying to dstoecker:

I have babel 1.3 as well and we got following report: https://josm.openstreetmap.de/ticket/10521 Is this related? It happens when trying to attach something to a wiki page. If yes, I probably need to open a bug for genshi?

That seems like an issue in Genshi 0.6.1/0.7 and has been filed in #11184 and genshi:#566. Please try to downgrade to 0.6.0 or use 0.6-stable/0.7-stable branch.

Last edited 4 years ago by Jun Omae (previous) (diff)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jun Omae.
The resolution will be deleted.
to The owner will be changed from Jun Omae to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.