Edgewall Software

Ticket #7253 (closed enhancement: worksforme)

Opened 6 months ago

Last modified 8 days ago

Safely disable translations to stop "AttributeError: translations"

Reported by: Pedro Algarvio, aka, s0undt3ch <ufs@…> Owned by: cmlenz
Priority: normal Milestone:
Component: i18n Version: 0.12dev
Severity: trivial Keywords: verify
Cc:

Description

Although this was found while working on a plugin, this could be avoided.

If one raises RequestDone too soon for a translation to be activated, one get's an AttributeError and this could be avoided by first checking if there's actually a translations attribute prior to deleting it.

A patch follows.

Attachments

safe.translations.attr.disable.patch (0.5 KB) - added by Pedro Algarvio, aka, s0undt3ch <ufs@…> 6 months ago.
traceback.txt (5.5 KB) - added by Pedro Algarvio, aka, s0undt3ch <ufs@…> 6 months ago.

Change History

Changed 6 months ago by Pedro Algarvio, aka, s0undt3ch <ufs@…>

  Changed 6 months ago by Pedro Algarvio, aka, s0undt3ch <ufs@…>

As a side note, this happens in both 0.11-table and 0.12dev

  Changed 6 months ago by cboos

  • milestone changed from 0.11 to 0.12

I doubt this could happen in 0.11-stable, as there's no deactivate() there. About 0.12dev, was the problem happening even with r7051?

  Changed 6 months ago by Pedro Algarvio, aka, s0undt3ch <ufs@…>

Replying to cboos:

I doubt this could happen in 0.11-stable, as there's no deactivate() there. About 0.12dev, was the problem happening even with r7051?

On the branch I currently have:

  • trac/util/translation.py

     
    111111        return getattr(_current, 'translations', _null_translations) 
    112112 
    113113    def deactivate(): 
    114         del _current.translations 
     114        if hasattr(_current, 'translations'): 
     115            del _current.translations 
    115116 
    116117    def get_available_locales(): 
    117118        """Return a list of locale identifiers of the locales for which 

And so that you know my branch:

svn info
Path: .
URL: http://svn.edgewall.org/repos/trac/branches/0.11-stable
Repository Root: http://svn.edgewall.org/repos/trac
Repository UUID: af82e41b-90c4-0310-8c96-b1721e28e2e2
Revision: 7072
Node Kind: directory
Schedule: normal
Last Changed Author: nkantrowitz
Last Changed Rev: 7071
Last Changed Date: 2008-05-16 10:19:19 +0100 (Fri, 16 May 2008)

So, it is present on 0.11-stable or am I lost somewhere?

Regarding 0.12dev on r7051, yes, the symptom also shows up as on r7087 .

  Changed 6 months ago by Pedro Algarvio, aka, s0undt3ch <ufs@…>

  • version changed from 0.11-stable to 0.12dev

Sorry, after switching again to the stable branch, I say you're right cboos, it does not happen on the 0.10-stable branch.

follow-up: ↓ 6   Changed 6 months ago by cboos

Well, never trust your working copy, use Trac :-) source:branches/0.11-stable/trac/util/translation.py

Ok, thanks for the confirmation that r7051 was not enough. Could you eventually post the full backtrace from the log?

in reply to: ↑ 5   Changed 6 months ago by Pedro Algarvio, aka, s0undt3ch <ufs@…>

Replying to cboos:

Well, never trust your working copy, use Trac :-) source:branches/0.11-stable/trac/util/translation.py Ok, thanks for the confirmation that r7051 was not enough. Could you eventually post the full backtrace from the log?

Sure but this was thrown when developing a plugin, normal use of trac does not seem to throw it. Anyway, attaching the traceback.

Changed 6 months ago by Pedro Algarvio, aka, s0undt3ch <ufs@…>

  Changed 5 months ago by cboos

  • keywords verify added
  • milestone changed from 0.13 to 0.12

I'm still not convinced this can happen in normal use, the plugin must do something quite weird (more info needed).

  Changed 4 months ago by palgarvio

Still happens on [7409]:

127.0.1.1 - - [27/Jul/2008 16:35:21] "GET / HTTP/1.1" 500 -
16:35:21 Trac[main] DEBUG: 304 unreachable objects found.
16:35:23 Trac[main] DEBUG: Dispatching <Request "GET u'/'">
16:35:23 Trac[session] DEBUG: Retrieving session for ID '4200ddb5e6bbb59fae27136b'
16:35:23 Trac[main] ERROR: translations
Traceback (most recent call last):
  File "/home/vampas/projects/HGTrac/trac/web/main.py", line 447, in _dispatch_request
    dispatcher.dispatch(req)
  File "/home/vampas/projects/HGTrac/trac/web/main.py", line 257, in dispatch
    translation.deactivate()
  File "/home/vampas/projects/HGTrac/trac/util/translation.py", line 114, in deactivate
    del _current.translations
AttributeError: translations

The only plugins activated are mercurial support and account manager; actually, with all plugins disabled it still happens.

I also get on browser:

Traceback (most recent call last):
  File "/home/vampas/projects/HGTrac/trac/web/api.py", line 344, in send_error
    data, 'text/html')
  File "/home/vampas/projects/HGTrac/trac/web/chrome.py", line 699, in render_template
    data = self.populate_data(req, data)
  File "/home/vampas/projects/HGTrac/trac/web/chrome.py", line 637, in populate_data
    'locale': req and req.locale,
  File "/home/vampas/projects/HGTrac/trac/web/api.py", line 170, in __getattr__
    value = self.callbacks[name](self)
  File "/home/vampas/projects/HGTrac/trac/web/main.py", line 281, in _get_locale
    return Locale.negotiate(preferred, available, sep='-')
  File "/home/vampas/projects/Babel/babel/core.py", line 181, in negotiate
    aliases=aliases)
  File "/home/vampas/projects/Babel/babel/core.py", line 699, in negotiate_locale
    ll = locale.lower()
AttributeError: 'list' object has no attribute 'lower'

Hmm, and this last one brings babel into the equation :\

  Changed 4 months ago by palgarvio

Sorry, this was trigged by a not that related bug found #7469.

Once fix is applied, the above no longer happens.

  Changed 8 days ago by cboos

  • status changed from new to closed
  • resolution set to worksforme
  • milestone 0.12 deleted

OK, #7469 is fixed, closing this one as well.

Add/Change #7253 (Safely disable translations to stop "AttributeError: translations")

Author



Change Properties
<Author field>
Action
as closed
Next status will be 'reopened'
to The owner will change from cmlenz. Next status will be 'closed'
 
Note: See TracTickets for help on using tickets.