You are most likely running into TG error handling. What happens is,
every call to an exposed method gets wrapped into a try-catch block. If
an exception occurs, it gets dispatched to the most suited (specialised)
error handler or, if there are none, to the originating method.
Under normal circumstances an infinite recursion prevention mechanism
should kick-in on second dispatch (on stack) to the same handler.
However in your case, the exception (being state dependant) is never
raised two consecutive times, therefore the stack gets emptied
in-between and the condition goes unnoticed.
I'm working on documentation for error handling as we speak. In the mean
time, you may want to look at turbogears/errorhandling.py,
turbogears/test/test_errorhandling.py and ticket #258 [1].
----
Does anybody think, we should make exception wrapping optional?
Cheers,
Simon
[1] http://trac.turbogears.org/turbogears/ticket/258
qvx wrote:
Try quickstaring new application (for example "test1"). Then change
index() method into:
_cnt = 0
@turbogears.expose(template="test1.templates.welcome")
def index(self):
import time
self._cnt += 1
print '***', self._cnt
if self._cnt%2 == 1:
a = 1/0
print '***', self._cnt, 'OK'
return dict(now=time.ctime())
Now run your application and visit it. Try refreshing it. See anything
strange?
All you get (in the log) is:
*** 1
*** 2
*** 2 OK
There are no errors whatsoever!!!
Exception is being hidden away.
Now, let me tell you. I spent several hours to track this down. I even
started to suspect the python implementation because my trace
statements were leading me into conclusion that python somehow discards
exceptions. It was only several hours later that I realized that
Turbogears was automatically retrying (i guess) requests. So, the
second time my code passed (conditions have changed) and it looked like
python had some error in exception handling.
What is happening?
qvx
P.S. I'm using latest svn version (692) on Windows XP.