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

Opened 11 years ago

Last modified 11 years ago

complex validators only allow a single render of a field or form

Reported by: kvaml Owned by: anonymous
Priority: normal Milestone:
Component: TurboGears Version: 1.0.3
Severity: normal Keywords:
Cc:

Description

Normally we can render a field repeatedly.

>>> from turbogears import widgets
>>> from turbogears import validators
>>> phone = widgets.TextField("phone",
...     validator=validators.PhoneNumber(),
...     label="Phone Number with area code")
>>> phone.render()
'<input id="phone" type="text" class="textfield" name="phone">'
>>> phone.render()
'<input id="phone" type="text" class="textfield" name="phone">'

However, if we add not_empty=True to the validator, only the first call to render works properly.

>>> phone = widgets.TextField("phone",
...     validator=validators.PhoneNumber(not_empty=True),
...     label="Phone Number with area code"
...     )
>>> phone.render()
'<input id="phone" type="text" class="textfield requiredfield" name="phone">'
>>> phone.render()
Traceback (most recent call last):
  File "<console>", line 1, in ?
  File "/usr/lib/python2.4/site-packages/TurboGears-1.0.3.2-py2.4.egg/turbogears/widgets/base.py", line 274, in render
    elem = self.display(value, **params)
  File "/usr/lib/python2.4/site-packages/TurboGears-1.0.3.2-py2.4.egg/turbogears/widgets/forms.py", line 51, in _update_path
    returnval = func(self, *args, **kw)
  File "/usr/lib/python2.4/site-packages/TurboGears-1.0.3.2-py2.4.egg/turbogears/widgets/forms.py", line 236, in display
    return super(InputWidget, self).display(value, **params)
  File "/usr/lib/python2.4/site-packages/TurboGears-1.0.3.2-py2.4.egg/turbogears/widgets/base.py", line 263, in display
    self.update_params(params)
  File "/usr/lib/python2.4/site-packages/TurboGears-1.0.3.2-py2.4.egg/turbogears/widgets/forms.py", line 451, in update_params
    if self.is_required:
  File "/usr/lib/python2.4/site-packages/TurboGears-1.0.3.2-py2.4.egg/turbogears/widgets/forms.py", line 429, in _get_is_required
    validator.to_python('')
  File "/usr/lib/python2.4/site-packages/FormEncode-0.7.1-py2.4.egg/formencode/api.py", line 357, in to_python
    raise Invalid(self.message('empty', state), value, state)
  File "/usr/lib/python2.4/site-packages/FormEncode-0.7.1-py2.4.egg/formencode/api.py", line 194, in message
    return trans(self._messages[msgName], **self.gettextargs) % kw
TypeError: ugettext() got an unexpected keyword argument 'domain'

I am using python2.4 on fedora 6. All packages were installed with easy_install. Hopefully the trace provides enough useful information.

Change History

comment:1 Changed 11 years ago by kvaml

I just tested on fedora 7 using python 2.5 and could not reproduce the problem. I'll make a detailed comparison of package versions and try to pin down the issue.

comment:2 Changed 11 years ago by kvaml

The version differences do not appear to be significant.

In [28]: for v in versionset:
   ....:     if worksmap[v] != failmap[v]: print '%16.16s\t%s\t%s' % (v,worksmap[v],failmap[v])
   ....: name           works   fails
          _mysql        1.2.2   1.2.1
         MySQLdb        1.2.2   1.2.1
       distutils        2.5.0   2.4.4
          urllib        1.17    1.16
      simplejson        1.7.1   1.3
        optparse        1.5.3   1.5a2
         urllib2        2.5     2.4
         logging        0.4.9.9 0.4.9.7
 MySQLdb.release        1.2.2   1.2.1
          pickle        $Revision: 38432 $      $Revision: 36861 $

The full list of modules from the python 2.4 failure

In [29]: faillist
Out[29]: 
[('BaseHTTPServer', '0.3'),
 ('MySQLdb', '1.2.1'),
 ('MySQLdb.release', '1.2.1'),
 ('SocketServer', '0.4'),
 ('_mysql', '1.2.1'),
 ('_xmlplus', '0.8.4'),
 ('cPickle', '1.71'),
 ('cgi', '2.6'),
 ('cherrypy', '2.2.1'),
 ('configobj', '4.4.0'),
 ('distutils', '2.4.4'),
 ('kid', '0.9.6'),
 ('kid.codewriter', '0.9.6'),
 ('kid.importer', '0.9.6'),
 ('logging', '0.4.9.7'),
 ('mx', '2.0'),
 ('mx.DateTime', '2.0.3'),
 ('mx.DateTime.DateTime', '2.0.3'),
 ('mx.DateTime.mxDateTime', '2.0.3'),
 ('mx.DateTime.mxDateTime.mxDateTime', '2.0.3'),
 ('optparse', '1.5a2'),
 ('parser', '0.5'),
 ('pickle', '$Revision: 36861 $'),
 ('setuptools', '0.6c7'),
 ('simplejson', '1.3'),
 ('sqlalchemy', '0.3.10'),
 ('sqlobject.include.pydispatch', '1.0.0'),
 ('sqlobject.include.pydispatch.dispatcher', '1.9'),
 ('sre', '2.2.1'),
 ('turbogears', '1.0.3.2'),
 ('turbogears.toolbox.admi18n.msgfmt', '1.1'),
 ('turbogears.toolbox.admi18n.pygettext', '1.5'),
 ('urllib', '1.16'),
 ('urllib2', '2.4'),
 ('validate', '0.2.3'),
 ('xml', '0.8.4'),
 ('xml.parsers.expat', '$Revision: 1.1 $'),
 ('xml.parsers.pyexpat', '2.88')]

I assume there is some unexpected difference between python 2.5 and 2.4.

comment:3 Changed 11 years ago by kvaml

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

The simple fix was to add

__metaclass__ = type

to the top of the controlers.py file!

The Form and Root classes inherited from widgets.TableForm? and controllers.RootController?, so it is not clear to me why this was necessary.

Note: See TracTickets for help on using tickets.