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

A dependency is not considered satisfied if it has a null value #305

Closed
derek-miller opened this Issue Apr 5, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@derek-miller
Copy link

derek-miller commented Apr 5, 2017

Used Cerberus version / latest commit: 1.1


Use-case abstract

A dependency is not considered satisfied if it has a null value.


Support request / Bug report

To reproduce:

>>> from cerberus import Validator
... validator = Validator(schema={
...     'field1': {
...         'required': False,
...         'nullable': True
...     },
...     'field2': {
...         'required': False,
...         'dependencies': 'field1'
...     }
... })
... document = {
...     'field1': None,
...     'field2': 'foo'
... }
... assert validator.validate(document), validator.errors
Traceback (most recent call last):
  File "<input>", line 16, in <module>
AssertionError: {'field2': ["field 'field1' is required"]}

This seems wrong considering required fields with a null value satisfy the required constraint, but not a dependency.

@funkyfuture

This comment has been minimized.

Copy link
Member

funkyfuture commented Apr 6, 2017

does it also behave that way when defined without dependency?

my suspicion is that what you observe is rooted here.

if a field that is defined as required shall also fail when its value is None (my guess for now would be that this is intended), that fact should be amended to the docs.

@derek-miller

This comment has been minimized.

Copy link

derek-miller commented Apr 6, 2017

No, a required field with a null value satisfies the required rule:

>>> from cerberus import Validator
... validator = Validator(schema={
...     'field1': {
...         'required': True,
...         'nullable': True
...     },
...     'field2': {
...         'required': False,
...         #'dependencies': 'field1'
...     }
... })
... document = {
...     'field1': None,
...     'field2': 'foo'
... }
>>> assert validator.validate(document), validator.errors
>>>

davidt99 pushed a commit to davidt99/cerberus that referenced this issue Apr 13, 2017

davidt99 added a commit to davidt99/cerberus that referenced this issue Apr 13, 2017

davidt99 added a commit to davidt99/cerberus that referenced this issue Apr 13, 2017

davidt99 added a commit to davidt99/cerberus that referenced this issue Apr 16, 2017

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

Fixes the lookup for dependency fields.
Before that a document field with None as value
was considered to be absent in the document.
Also gets the nullable rule's constraint from
Validator.ignore_none_values in case that one may
not be the default. Amended docs to clarify that.

Fixes pyeve#305

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

Fixes the lookup for dependency fields.
Before that a document field with None as value
was considered to be absent in the document.
Also gets the nullable rule's constraint from
Validator.ignore_none_values in case that one may
not be the default. Amended docs to clarify that.

Fixes pyeve#305

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

Fixes the lookup for dependency fields.
Before that a document field with None as value
was considered to be absent in the document.
Also gets the nullable rule's constraint from
Validator.ignore_none_values in case that one may
not be the default. Amended docs to clarify that.

Fixes pyeve#305

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

Fixes the lookup for dependency fields.
Before that a document field with None as value
was considered to be absent in the document.
Also gets the nullable rule's constraint from
Validator.ignore_none_values in case that one may
not be the default. Amended docs to clarify that.

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