-
Notifications
You must be signed in to change notification settings - Fork 238
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
dependencies #138
Comments
Your schema implies that
Since your documents only have |
It seems that with dependency on Dependency on schema = {'deleted': {'type': 'string'}, 'text': {'dependencies': {'deleted':['foo', 'bar']}}}
doc = {'text':'abc', 'deleted':'q'}
v.validate(doc, schema)
v.errors
{'text': "field '('deleted', ['foo', 'bar'])' is required with values: ('deleted', ['foo', 'bar'])"}
schema = {'deleted': {'type': 'boolean'}, 'text': {'dependencies': {'deleted':True}}}
doc = {'text':'abc'}
v.validate(doc, schema)
v.errors
{'text': "field '('deleted', True)' is required with values: ('deleted', True)"}
schema = {'deleted': {'type': 'boolean'}, 'text': {'dependencies': {'deleted':True}}}
doc = {'text':'abc', 'deleted': 1}
v.validate(doc, schema)
v.errors
{'deleted': 'must be of boolean type'}
schema = {'deleted': {'type': 'boolean'}, 'text': {'dependencies': {'deleted':[True]}}}
doc = {'text':'abc', 'deleted': False}
v.validate(doc, schema)
True
schema = {'deleted': {'type': 'boolean'}, 'text': {'dependencies': {'deleted':True}}}
doc = {'text':'abc', 'deleted': False}
v.validate(doc, schema)
True |
Yeah I noticed that too. |
Actual github code (branch master) has different behaviour, works correct with def main():
v = cerberus.Validator()
schema = {'deleted': {'type': 'string'},
'text': {'dependencies': {'deleted': 'foo'}}}
doc = {'text': 'abc', 'deleted': 'bar'}
print(v.validate(doc, schema))
print(v.errors, '\n')
schema = {'deleted': {'type': 'boolean'},
'text': {'dependencies': {'deleted': [True]}}}
doc = {'text':'abc', 'deleted': False}
print(v.validate(doc, schema))
print(v.errors, '\n')
schema = {'deleted': {'type': 'boolean'},
'text': {'dependencies': {'deleted': True}}}
doc = {'text':'abc', 'deleted': False}
print(v.validate(doc, schema))
print(v.errors, '\n') ~/Developer/cerberus master ✗
▶ python3 test_bool_depend.py
False
{'text': "field 'deleted' is required with one of these values: ['foo']"}
False
{'text': "field 'deleted' is required with one of these values: [True]"}
Traceback (most recent call last):
File "test_bool_depend.py", line 27, in <module>
main()
File "test_bool_depend.py", line 22, in main
print(v.validate(doc, schema))
File "/Users/devilandall/Developer/cerberus/cerberus/cerberus.py", line 427, in validate
self.__validate_definition(definition, field)
File "/Users/devilandall/Developer/cerberus/cerberus/cerberus.py", line 509, in __validate_definition
self._validate_dependencies(definition, field, value) or
File "/Users/devilandall/Developer/cerberus/cerberus/cerberus.py", line 543, in _validate_dependencies
self.__validate_dependencies_mapping(dependencies, field)
File "/Users/devilandall/Developer/cerberus/cerberus/cerberus.py", line 559, in __validate_dependencies_mapping
if context in dep_values:
TypeError: argument of type 'bool' is not iterable |
Fixed with #139 |
Has something gone wrong with dependencies checking, or I simply do not get the way it is supposed to work?
schema = {'text':{'dependencies':{'deleted':False}}, 'deleted':{'type':'boolean'}}
test = {'deleted':True}
v.validate(test, schema)
True
test = {'deleted':False}
v.validate(test, schema)
True
I use 0.9.1
The text was updated successfully, but these errors were encountered: