Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#100 TimeConverter bug when seconds are not a number

closed-fixed
nobody
None
5
2010-05-16
2010-05-06
Anonymous
No

When trying to convert a time value like "6:00:abc", formencode fails with __init__ invalid argument count instead of Invalid(badNumber).

Ex:

>>> from formencode.validators import TimeConverter
>>> d = TimeConverter()
>>> d.to_python('6:00:a')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "formencode/api.py", line 413, in to_python
value = tp(value, state)
File "formencode/validators.py", line 2141, in _to_python
result = self._to_python_tuple(value, state)
File "formencode/validators.py", line 2231, in _to_python_tuple
number=parts[2], part='second'))
TypeError: __init__() takes at least 4 arguments (2 given)

Looks like there are some paremeters missing in validator.py line 2231:

2230 self.message('badNumber', state,
2231 number=parts[2], part='second'))

after changing it to:

2230 self.message('badNumber', state,
2231 number=parts[2], part='second'),
2232 value, state)

error is handled ok:

>>> from formencode.validators import TimeConverter
>>> d = TimeConverter()
>>> d.to_python('6:00:a')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "formencode/api.py", line 413, in to_python
value = tp(value, state)
File "formencode/validators.py", line 2141, in _to_python
result = self._to_python_tuple(value, state)
File "formencode/validators.py", line 2232, in _to_python_tuple
value, state)
formencode.api.Invalid: The second value you gave is not a number: 'a'

Discussion

    • status: open --> closed-fixed
     
  • Found that I fixed this already in changeset 838e979f61f2.