[TurboGears] master.kidをいじると、"TypeError: 'NoneType' object is not callable"が発生する、ことがある。
環境
この記事の内容は、TurboGears 1.0.1で確認しました。
現象
master.kidを書き換えると、以下のエラーが発生します。
500 Internal error
The server encountered an unexpected condition which prevented it from fulfilling the request.
Page handler: >
Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/CherryPy-2.2.1-py2.4.egg/cherrypy/_cphttptools.py", line 105, in _run
self.main()
File "/usr/lib/python2.4/site-packages/CherryPy-2.2.1-py2.4.egg/cherrypy/_cphttptools.py", line 254, in main
body = page_handler(*virtual_path, **self.params)
File "", line 3, in index
File "/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/turbogears/controllers.py", line 334, in expose
output = database.run_with_transaction(
File "", line 5, in run_with_transaction
File "/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/turbogears/database.py", line 302, in so_rwt
retval = func(*args, **kw)
File "", line 5, in _expose
File "/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/turbogears/controllers.py", line 351, in
mapping, fragment, args, kw)))
File "/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/turbogears/controllers.py", line 391, in _execute_func
return _process_output(output, template, format, content_type, mapping, fragment)
File "/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/turbogears/controllers.py", line 82, in _process_output
fragment=fragment)
File "/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/turbogears/view/base.py", line 131, in render
return engine.render(**kw)
File "/usr/lib/python2.4/site-packages/TurboKid-0.9.8-py2.4.egg/turbokid/kidsupport.py", line 156, in render
return t.serialize(encoding=self.defaultencoding, output=format, fragment=fragment)
File "/usr/lib/python2.4/site-packages/kid-0.9.3-py2.4.egg/kid/__init__.py", line 236, in serialize
return serializer.serialize(self, encoding, fragment)
File "/usr/lib/python2.4/site-packages/kid-0.9.3-py2.4.egg/kid/serialization.py", line 51, in serialize
text = list(self.generate(stream, encoding, fragment))
File "/usr/lib/python2.4/site-packages/kid-0.9.3-py2.4.egg/kid/serialization.py", line 326, in generate
stream = iter(stream)
File "/usr/lib/python2.4/site-packages/kid-0.9.3-py2.4.egg/kid/__init__.py", line 261, in __iter__
return iter(self.transform())
File "/usr/lib/python2.4/site-packages/kid-0.9.3-py2.4.egg/kid/__init__.py", line 316, in transform
stream = self.pull()
File "/usr/lib/python2.4/site-packages/kid-0.9.3-py2.4.egg/kid/__init__.py", line 275, in pull
self.initialize()
File "/home/tom/projects/CalciumRider/car/templates/article/search/index.py", line 21, in initialize
File "/home/tom/projects/CalciumRider/car/templates/master.py", line 21, in initialize
TypeError: 'NoneType' object is not callable
この現象の再現性は低く、発生するときとしないときがあります。
原因
分かりません。
詳細
ときを改めて、以下のRubyスクリプトを実行して、エラーが発生したURLを10000回リクエストし、エラーが発生する回数を計測してみました。
# ruby require "open-uri" count = 0 10000.times do open("http://127.0.0.1:8080/article/list") do |f| if 0 < f.grep(/Internal error/).size() count += 1 end end end puts count # vim: tabstop=2 shiftwidth=2 expandtab
結果は、0でした(1回もエラーにならなかった)。原因がはっきりしないまま、発生しなくなりました。
所感
一体、なんだったんだろう...。