Skip to content
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

nullable rule doesn't work in conjunction with anyof* rules #582

Closed
dkbarn opened this issue Jan 16, 2022 · 0 comments
Closed

nullable rule doesn't work in conjunction with anyof* rules #582

dkbarn opened this issue Jan 16, 2022 · 0 comments

Comments

@dkbarn
Copy link

dkbarn commented Jan 16, 2022

Used Cerberus version: 1.3.4

Use-case abstract

There is a value in my schema that can be an integer or a string or null.

Bug report

This seems like a bug, because as soon as I try to introduce an anyof* rule, the nullable rule is no longer respected.

nullable works with only a single type. The following validate() call returns True.

schema = {"foo": {"type": "integer", "nullable": True}}
Validator(schema).validate({"foo": None})

nullable stops working with multiple possible types. All of the following validate() calls erroneously return False.

schema = {"foo": {"anyof_type": ["integer", "string"], "nullable": True}}
Validator(schema).validate({"foo": None})
schema = {"foo": {"anyof": [{"type": "integer"}, {"type": "string"}, {"nullable": True}]}}
Validator(schema).validate({"foo": None})
schema = {"foo": {"anyof": [{"type": "integer", "nullable": True}, {"type": "string", "nullable": True}, {"nullable": True}]}}
Validator(schema).validate({"foo": None})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant