Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2443 (closed defect: fixed)

Opened 10 years ago

Last modified 9 years ago

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:


import turbogears as tg

class MyWidget(tg.widgets.Widget):
    template = """
    <div>hello world</div>

class Module1(object):
    class widget(MyWidget):
m1 = Module1()
w1 = m1.widget()

class Module2(object):
    class widget(MyWidget):
m2 = Module2()
w2 = m2.widget()


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".


meta.patch Download (1.1 KB) - added by xaka 10 years ago.
fix_and_test_case.diff Download (1.6 KB) - added by xaka 9 years ago.

Change History

Changed 10 years ago by xaka

comment:1 Changed 9 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 9 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 9 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 9 years ago by xaka

Okay, tested with 1.1 and issue is still here. Attached patch fixes the problem.

Changed 9 years ago by xaka

comment:5 Changed 9 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


comment:6 Changed 9 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 9 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.

comment:8 Changed 9 years ago by chrisz

@xaka: Thank you for these valuable patches. If you want to be listed as contributor for the upcoming TG bugfix release, let me (cito at online de) know your real name.

Note: See TracTickets for help on using tickets.