#11: Python formencode doesn't run validations when input is None

Using FormEncode 1.0.1, validations don't seem to run when an input value of None is provided to the FancyValidator.to_python or Schema.to_python method.

Example

validation schema:
class ValidToken(formencode.FancyValidator): def _to_python(self, value, state): if value == None raise formencode.Invalid( "Must have a value", value, state) return value

controller:
# controller method input_val = None try: val = ValidToken.to_python(input_val) except formencode.Invalid, e: return "Failed due to invalid value" return "OK"

The expected output: Failed due to invalid value

Actual output: OK

Think you've got a solution? Help 92049143cabb7ba896d7c06e19906303_small yliu out by posting your solution

FormEncode Validation — FormEncode v1.2.1 documentation

http://formencode.org/Validator.html#other-validator-usage - found by 92049143cabb7ba896d7c06e19906303_small yliu on February 07, 2009, 11:31 AM UTC

not_empty can be used to explicitly specify that non-empty values should raise an error