Pylons error "No object (name: request) has been registered for this thread" with debug = false

Posted by Evgeny on Stack Overflow See other posts from Stack Overflow or by Evgeny
Published on 2010-03-22T22:55:24Z Indexed on 2010/03/22 23:01 UTC
Read the original article Hit count: 543

Filed under:
|
|
|

I'm unable to access the request object in my Pylons 0.9.7 controller when I set debug = false in the .ini file. I have the following code:

def run_something(self):
    print('!!! request = %r' % request)
    print('!!! request.params = %r' % request.params)
    yield 'Stuff'

With debugging enabled this works fine and prints out:

!!! request = <Request at 0x9571190 POST http://my_url>
!!! request.params = UnicodeMultiDict([... lots of stuff ...])

If I set debug = false I get the following:

!!! request = <paste.registry.StackedObjectProxy object at 0x4093790>
Error - <type 'exceptions.TypeError'>: No object (name: request) has been registered for this thread

The stack trace confirms that the error is on the print('!!! request.params = %r' % request.params) line.

I'm running it using the Paste server and these two lines are the very first lines in my controller method.

This only occurs if I have yield statements in the method (even though the statements aren't reached). I'm guessing Pylons sees that it's a generator method and runs it on some other thread. My questions are:

  1. How do I make it work with debug = false ?
  2. Why does it work with debug = true ? Obviously this is quite a dangerous bug, since I normally develop with debug = true, so it can go unnoticed during development.

© Stack Overflow or respective owner

Related posts about python

Related posts about pylons