Skip to content

IPAddress validator does not respect not_empty, if_missing or if_invalid_python #120

Open

Description

@NucleaPeon

I have a schema with an IPAddress validator. The IP address is optional so the validation cannot raise errors when the ip field is missing. However, options that are supposed to allow fields to accept empty values do not work with this validator type.

Schema:

class IPTest(formencode.Schema):
    ip = validators.IPAddress(not_empty=False, if_missing=None, if_invalid_python=None)

Action:

IPTest().to_python({"ip": "asdf"})

Expected Result: {"ip": None}

Actual Result:

>>> IPTest().to_python({"ip": "asdf"})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/dist-packages/formencode/api.py", line 476, in to_python
    value = tp(value, state)
  File "/usr/local/lib/python3.4/dist-packages/formencode/schema.py", line 217, in _convert_to_python
    value_dict, state, error_dict=errors)
formencode.api.Invalid: ip: Please enter a valid IP address (a.b.c.d)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions