Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#119 Current All compound validator behaves like Pipe

closed
nobody
None
5
2011-09-25
2011-09-24
No

This leads to various issues like:

>>> All(validators=[Int, Bool]).to_python('yes')
1

even though it should fail as yes is 'yes' not an Int.

Also the fact that FormEncode mixes validation and conversion is an issue in All.

>>> All(validators=[Int, Bool]).to_python('1')
1

I get 1 even though I probably wanted a True.
Currently All is an inverse Pipe with an odd name.

A proposed solution is to add a "converter" parameter to All, in the case this parameter is available the validators are applied on the original value instead of being used on the output of the previous validator and only converter is used to provide the requested output.

>>> All(validators=[Int, Bool], converter=Bool).to_python('yes')
Invalid

>>> All(validators=[Int, Bool], converter=Bool).to_python('1')
True

Discussion

  • plantian
    plantian
    2011-09-25

    All evaluates the validators from right to left when converting to python. So Int.to_python(Bool.to_python('yes')) == 1. I think everyone is in agreement that the order is not intuitive since everyone predominantly does to_python validation. I added some documentation and I think people will start using Pipe. There is just too much code using All to change it I think.

    I think the converter argument idea your describe might fit in with a different kind of validator. I think on IRC I mentioned the term Every. Maybe that could be added in the future with a few solid use cases.

     
    • status: open --> closed