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 #2462 (closed defect: invalid)

Opened 9 years ago

Last modified 9 years ago

member variable in Form called 'method', causing exception

Reported by: rmancy Owned by:
Priority: normal Milestone: 1.0.x bugfix
Component: TG Widgets Version: 1.0.8
Severity: normal Keywords:


TurboGears 1.0.8 Python 2.4.3

I have this widget. It does not seem to work because of the 'self.method' member variable. I get the stacktrace below

class ReserveWorkflow(Form):
    member_widgets = ['method']
    params = []
    def __init__(self,*args,**kw):
        super(ReserveWorkflow,self).__init__(*args, **kw)
        self.method = SingleSelectField(name='method', label='Method', options=[(-1,'None')] + [(elem,elem) for elem in model.Distro.all_methods()])

raceback (most recent call last):
  File "/usr/lib/python2.4/site-packages/cherrypy/_cphttptools.py", line 121, in _run
  File "/usr/lib/python2.4/site-packages/cherrypy/_cphttptools.py", line 264, in main
    body = page_handler(*virtual_path, **self.params)
  File "<string>", line 3, in index
  File "/usr/lib/python2.4/site-packages/turbogears/controllers.py", line 358, in expose
    output = database.run_with_transaction(
  File "<string>", line 5, in run_with_transaction
  File "/usr/lib/python2.4/site-packages/turbogears/database.py", line 410, in sa_rwt
    retval = func(*args, **kw)
  File "<string>", line 5, in _expose
  File "/usr/lib/python2.4/site-packages/turbogears/controllers.py", line 373, in <lambda>
    mapping, fragment, args, kw)))
  File "/usr/lib/python2.4/site-packages/turbogears/controllers.py", line 410, in _execute_func
    output = errorhandling.try_call(func, *args, **kw)
  File "/usr/lib/python2.4/site-packages/turbogears/errorhandling.py", line 77, in try_call
    return func(self, *args, **kw)
  File "/home/raymond/dev/Beaker/test3/Server/beaker/server/reserve_workflow.py", line 13, in index
    widget = ReserveWorkflowWidget()
  File "/usr/lib/python2.4/site-packages/turbogears/widgets/meta.py", line 175, in widget_init
    validator = generate_schema(self.validator, widgets)
  File "/usr/lib/python2.4/site-packages/turbogears/widgets/meta.py", line 283, in generate_schema
    if widget.is_named:
AttributeError: 'Element' object has no attribute 'is_named'

Now if I change it to 'self.method_' (notice the trailing underscore) and obviously change the corersponding entry in member_widgets and in the template, then it works fine.

Not sure what the problem is. Maybe something to do with the iter_member_widgets generator object ??

Change History

comment:1 Changed 9 years ago by xaka

If you take a look on Form's class definition:

class Form(FormFieldsContainer):
    form = True
    name = "form"
    member_widgets = ["submit"]
    params = ["action", "method", "form_attrs", "use_name", "submit_text"]

You can see that method already defined as widget's parameter. Parameters can be not just a value, but a callable object. If parameter is callable it will be called _before_ passing to widget's template. Also it will be called when you'll try to access to that parameter via dot-notation (my_widget.method).

What did you? In your class you assign instance of SingleSelectField? to method variable. SingleSelectField? is the widget. Every widget is callable object. At call time it returns ElementStream/Element? instance. Also you define method as member widget which already defined as widget's parameter.

At the render time TG's internal code tried to access to your member widget method, which is parameter too, and expected to get Widget-base instance, but got Element instance. Why? Because method is the parameter, it has instance of some widget and as we know - every widget is the callable object.

comment:2 Changed 9 years ago by rmancy

Thanks for the explanation. I thought something like this must've been happening and I must have been overwriting a name that was already being used. Thanks again, sorry for the bother

comment:3 Changed 9 years ago by Chris Arndt

  • Status changed from new to closed
  • Component changed from TurboGears to TG Widgets
  • Resolution set to invalid

comment:4 Changed 9 years ago by chrisz

  • Milestone changed from __unclassified__ to 1.0.x bugfix
Note: See TracTickets for help on using tickets.