Ticket #2443 (closed defect: fixed)
Exception "TypeError: 'NoneType' object is not callable" on render widgets
| Reported by: | xaka | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.1.1 |
| Component: | TurboGears | Version: | 1.1 |
| Severity: | normal | Keywords: | |
| Cc: |
Description
import turbogears as tg
tg.view.load_engines()
class MyWidget(tg.widgets.Widget):
template = """
<div>hello world</div>
"""
class Module1(object):
class widget(MyWidget):
pass
m1 = Module1()
w1 = m1.widget()
class Module2(object):
class widget(MyWidget):
pass
m2 = Module2()
w2 = m2.widget()
w1.render()
w2.render()
Problem in turbogears.widgets.meta module. To generate template's module name it uses the following algo:
modname = "%s.%s" % (cls.__module__.__name__, cls.__name__)
In example above we have 2 different classes (Module1.widget == class1 and Module2.wiget == class2) with same names and living in same module i.e. modname for class1 == modname for class2. As result when we initiate class2 with existing modname in sys.modules it destroys prev template's module for class1 and during rendering we get the exception.
You can write your own fix for that issue. Attached patch is just "way to fix".
Attachments
Change History
comment:1 Changed 2 years ago by Chris Arndt
Thanks for your error reports, xaka. But going forward, could you please test your issues against the latest 1.x release (which is currently 1.1, soon 1.1.1) first?
The 1.0.9 version will only receive critical bug-fixes, since Tg 1.0.x is in maintenance mode.
comment:2 Changed 2 years ago by xaka
Uppps, sorry, my bad, will do. It just because we've use 1.0.x branch in our product and hope will see 1.0.10? :).
What about this issue? I should recheck it with 1.1?
comment:3 Changed 2 years ago by Chris Arndt
If you could, yes please. Or even with a checkout from /branches/1.1, if you want.
Re a future 1.0.10: maybe, but it's not high on our priority list unless a serious issue is discovered in 1.0.9.
comment:4 Changed 2 years ago by xaka
Okay, tested with 1.1 and issue is still here. Attached patch fixes the problem.
comment:5 Changed 2 years ago by xaka
I've attach more simple fix (remove modname, same logic uses in Widget's constructor) and test case for that issue.
meta.patch attachment can be removed
xaka@ubuntu:~/work/turbogears$ svn info URL: http://svn.turbogears.org/branches/1.1
---------------------------------------------------------------------- Ran 438 tests in 39.299s OK
comment:6 Changed 2 years ago by chrisz
- Version changed from 1.0.9 to 1.1
- Milestone changed from __unclassified__ to 1.1.1
Ok, I'll look into that issue this week.
comment:7 Changed 2 years ago by chrisz
- Status changed from new to closed
- Resolution set to fixed
Fixed as suggested in r7007 for the TG 1.1 and 1.5 branches. Note that TG 1.5 now uses Genshi templates for widgets by default, where this is not an issue because they don't use the constructed mod_name. However, Kid templates can still be used, so I fixed it there as well.
