-
Notifications
You must be signed in to change notification settings - Fork 241
Open
Labels
Description
Use-case abstract
According to docs readonly
parameter should give False on validation if field with that parameter is in dict.
Works as expected in general case:
import cerberus
schema_one = {
'id': {'type': 'integer', 'readonly': True},
'text': {'type': 'string', 'required': True}
}
schema_two = {
'id': {'type': 'integer', 'readonly': True},
'extra_text': {'type': 'string', 'required': True}
}
v = cerberus.Validator({'record': {'type': 'dict', 'schema': schema_one}})
test_data = {'record': {'id': 10, 'text': 'ooops'}}
v.validate(test_data)
# -> False
v.errors
# -> {'record': [{'id': ['field is read-only']}]}
Support request / Bug report
However using multiple schemas with oneof
for field will produce unexpected True
.
import cerberus
schema_one = {
'id': {'type': 'integer', 'readonly': True},
'text': {'type': 'string', 'required': True}
}
schema_two = {
'id': {'type': 'integer', 'readonly': True},
'extra_text': {'type': 'string', 'required': True}
}
v = cerberus.Validator({'record': {'type': 'dict', 'oneof_schema': [schema_one, schema_two]}})
test_data = {'record': {'id': 10, 'text': 'ooops'}}
v.validate(test_data)
# -> True
v.errors
# -> {}
anyof
gives same result, not tested with noneof
and allof
.
Bug exists in version 1.1, 1.0.x, in 9.x exception is raised when using readonly
param.