New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'coerce' ignores 'nullable': True #269

Closed
andreymal opened this Issue Sep 25, 2016 · 3 comments

Comments

Projects
None yet
4 participants
@andreymal
Copy link

andreymal commented Sep 25, 2016

>>> 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).

@funkyfuture

This comment has been minimized.

Copy link
Member

funkyfuture commented Oct 26, 2016

this is similar to #268.

@belthaZornv

This comment has been minimized.

Copy link

belthaZornv commented Feb 27, 2017

Bump, this makes sense.. is there any possibility to get this?

funkyfuture added a commit to funkyfuture/cerberus that referenced this issue Apr 21, 2017

@sohaibfarooqi

This comment has been minimized.

Copy link

sohaibfarooqi commented Nov 23, 2017

Is this feature released? I am using version 1.1, still facing this issue

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