Closed
Description
>>> v = Validator({'foo': {'type': 'integer', 'coerce': int, 'nullable': True}})
>>> v.validate({'foo': None})
False
>>> v.errors
{'foo': ["field 'foo' cannot be coerced: int() argument must be a string, a bytes-like object or a number, not 'NoneType'"]}
but expected:
>>> v.validate({'foo': None})
True
>>> v.errors
{}
>>> v.normalized({'foo': None})
{'foo': None}
This behavior can be logical (i can set something like 'coerce': lambda x: int(x) if x is not None else None
), but I do not think it's convenient, because I have to specify nullable
rule twice: in schema and in callable. I think, nullable
should be checked first, and if value is None, then coerce
callable should not be called.
If it's a bug and if architecture allows to fix this, please fix this :)
If it's a feature, please add a note about nullable
in value coercion documentation (better with an example).
Metadata
Metadata
Assignees
Labels
No labels