Pylons error "No object (name: request) has been registered for this thread" with debug = false
- by Evgeny
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:
How do I make it work with debug = false ?
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.