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

Opened 11 years ago

Last modified 11 years ago

TypeError in formencode.Schema._to_python when trying to render a twForm

Reported by: bruno.desthuilliers Owned by: alberto
Priority: normal Milestone:
Component: ToscaWidgets Version: trunk
Severity: normal Keywords:
Cc:

Description

Trying to follow the Pylons/twForms tutorial ( http://wiki.pylonshq.com/display/toscawidgets/Using+twForms+with+Pylons.+Part+1)

I get the following traceback when trying to render the form:

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/local/src/ToscaWidgets/toscawidgets/core.py", line 461, in __call__    return self.display(value, **kw)
  File "/usr/local/src/ToscaWidgets/toscawidgets/core.py", line 457, in display
    kw = self.prepare_dict(value, kw)
  File "/usr/local/src/ToscaWidgetsForms/toscawidgets/widgets/forms/core.py", line 191, in prepare_dict
    kw = super(InputWidget, self).prepare_dict(value, kw, adapt=False)
  File "/usr/local/src/ToscaWidgets/toscawidgets/core.py", line 501, in prepare_dict
    self.update_params(d)
  File "/usr/local/src/ToscaWidgetsForms/toscawidgets/widgets/forms/fields.py", line 239, in update_params
    super(Form, self).update_params(d)
  File "/usr/local/src/ToscaWidgetsForms/toscawidgets/widgets/forms/fields.py", line 107, in update_params
    super(FormField,self).update_params(d)
  File "/usr/local/src/ToscaWidgetsForms/toscawidgets/widgets/forms/core.py", line 207, in update_params
    super(InputWidget, self).update_params(d)
  File "/usr/local/src/ToscaWidgets/toscawidgets/core.py", line 568, in update_params
    attr = getattr(self,k,None)
  File "/usr/local/src/ToscaWidgetsForms/toscawidgets/widgets/forms/fields.py", line 89, in is_required
    self.validate('', use_request_local=False)
  File "/usr/local/src/ToscaWidgetsForms/toscawidgets/widgets/forms/core.py", line 129, in validate
    value =  self.validator.to_python(value, state)
  File "/usr/local/src/FormEncode/formencode/api.py", line 380, in to_python
    value = tp(value, state)
  File "/usr/local/src/FormEncode/formencode/schema.py", line 164, in _to_python    except KeyError:
TypeError: unbound method message() must be called with DefaultValidator instance as first argument (got str instance instead)

using FormEncode 0.7.2dev-r3105, ToscaWidgets? 0.1a2dev-r3614 and twForms 0.1a2dev-r3616.

The problem seems to come from the form's schema validators all being the DefaultValidator class itself, on which Schema._to_python calls the instance method message(). The relevant part of code is in formencode.schema, lines 152 to 173. I first thought there was a typo with InputWidget using the DefaultValidator class (instead of an instance of...), but it looks like it's by design since there are a couple of places where InputWidget.validator is identity tested against DefaultValidator, so...

NB : of course, the form renders ok when validators are explicitely added to the fields.

Attachments

test_message.py Download (422 bytes) - added by alberto 11 years ago.

Change History

comment:1 Changed 11 years ago by alberto

This seems like a FE bug (or a bug in the way twForms interacts with FE). I can reproduce with FormEncode 0.7.2dev-r3105 but not with 0.7.1. I'll try to investigate this a soon as I have a chance, though I wouldn't mind someone doing it before I do. :)

Thanks for the report!

Alberto

BTW: FE validator classes can be used as instances thanks to some dark magic inside formencode.declarative so yes, it's by design :)

comment:2 Changed 11 years ago by alberto

  • Status changed from new to closed
  • Resolution set to invalid

Its definitively a FE bug (unless the API has changed, of course), attached is a unittest that proves it. I'm forwarding it to the FE list

Alberto

Changed 11 years ago by alberto

Note: See TracTickets for help on using tickets.