#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:
   1  class ValidToken(formencode.FancyValidator):
   2      def _to_python(self, value, state):
   3          if value == None
   4              raise formencode.Invalid(
   5                  "Must have a value", value, state)
   6          return value


controller:
   1  # controller method
   2          input_val = None
   3          try:
   4              val = ValidToken.to_python(input_val)
   5          except formencode.Invalid, e:
   6              return "Failed due to invalid value"
   7          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