i18n via CherryPy sessions, TurboMail threads, and KID don't mix.

29 views
Skip to first unread message

Matthew Bevan

unread,
Oct 11, 2006, 2:53:03 PM10/11/06
to turbo...@googlegroups.com
In fact, very bad things(TM) happen.  A user of TurboMail brought the issue to my attention, and now that I need to use sessions in my current project, I have also run into it.  The problem is pretty simple: with sessions enabled, KID attempts to get the current locale from the session, even when the current request (and thus session) are not available.

Adding the following two lines to the top of _get_locale in turbogears/i18n/utils.py fixes the problem:

if not request_available():
return config.get("i18n.default_locale", "en")

My log and traceback:

2006-10-11 11:22:45,212 turbomail.pool DEBUG Estimate 1 work units in the queue.
2006-10-11 11:22:45,213 turbomail.pool DEBUG Creating 1 threads.
2006-10-11 11:22:45,214 turbomail.pool DEBUG Thread pool worker starting up.
2006-10-11 11:22:45,214 turbomail.dispatch DEBUG Creating SMTP object.
2006-10-11 11:22:47,322 turbomail.pool DEBUG Worker starting work.
2006-10-11 11:22:47,323 turbomail.dispatch INFO Connecting to SMTP server mail.topfloor.ca.
2006-10-11 11:22:49,999 turbomail.dispatch DEBUG TLS enabled on SMTP server.
2006-10-11 11:22:50,000 turbomail.dispatch DEBUG Authenticating as topfloor.
2006-10-11 11:22:50,120 turbokid.kidsupport DEBUG Compiling template for healinghands.templates.mail.welcome
Exception in thread Thread-15:
Traceback (most recent call last):
  File ".../python2.4/threading.py", line 442, in __bootstrap
    self.run()
  File ".../python2.4/threading.py", line 422, in run
    self.__target(*self.__args, **self.__kwargs)
  File ".../turbomail/pool.py", line 113, in wrapper
  File ".../turbomail/pool.py", line 166, in worker
  File ".../turbomail/dispatch.py", line 129, in __call__
  File "b.../turbomail/message.py", line 169, in __call__
  File ".../turbomail/message.py", line 223, in _process
  File ".../TurboKid-0.9.8-py2.4.egg/turbokid/kidsupport.py", line 165, in transform
    data.update(self.get_extra_vars())
  File ".../TurboGears-1.0b1-py2.4.egg/turbogears/view/base.py", line 319, in stdvars
    locale = get_locale(),
  File ".../TurboGears-1.0b1-py2.4.egg/turbogears/i18n/utils.py", line 51, in get_locale
    locale = get_locale_f()
  File ".../TurboGears-1.0b1-py2.4.egg/turbogears/i18n/utils.py", line 62, in _get_locale
    locale = cherrypy.session.get(locale_key)
  File ".../CherryPy-2.2.1-py2.4.egg/cherrypy/filters/sessionfilter.py", line 431, in __getattr__
    sess = cherrypy.request._session
  File ".../CherryPy-2.2.1-py2.4.egg/cherrypy/__init__.py", line 42, in __getattr__
    childobject = getattr(serving, self.__attrname__)
AttributeError: 'thread._local' object has no attribute 'request'

Making the modification to my local copy of TG-1.0b1 makes TurboMail happy when using KID templates outside of a request with sessions enabled.

Matthew Bevan, Systems Administrator
Top Floor Computer Systems Ltd.


Lee McFadden

unread,
Oct 11, 2006, 3:14:43 PM10/11/06
to turbo...@googlegroups.com
This looks like a Trac Ticket + Patch to me :) Create a ticket (even
without the patch if you don't have SVN available) and reply to the
thread with the ticket's link and I'll make sure it's tested and
committed.

Lee


--
Lee McFadden

blog: http://www.splee.co.uk
work: http://fireflisystems.com

Matthew Bevan

unread,
Oct 11, 2006, 3:14:49 PM10/11/06
to turbo...@googlegroups.com
I have created a ticket with a patch:

Lee McFadden

unread,
Oct 11, 2006, 4:01:22 PM10/11/06
to turbo...@googlegroups.com
Comitted.

On 10/11/06, Matthew Bevan <matt....@topfloor.ca> wrote:
>

Reply all
Reply to author
Forward
0 new messages