You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Cerberus API allows custom validation properties and custom validation types to be added by creating a class that inherits from cerberus.Validator. It also allows validation rules to be supplied for arbitrary fields, via the allow_unknown property. However, the schema for unknown properties cannot make use of custom validation properties and custom validation types.
For example:
from cerberus import Validator
class CustomValidator(Validator):
def _validate_type_foo(self, field, value):
if not value == "foo":
self.error(field, "Expected a foo")
v = CustomValidator({})
v.allow_unknown = {"type": "foo"}
v.validate( { "fred": "foo", "barney": "foo" } )
I would expect the call to .validate() to approve that document, but instead
I get a traceback:
Traceback (most recent call last):
File "test-cerberus.py", line 13, in <module>
v.validate( { "fred": "foo", "barney": "foo" } )
File "cerberus/cerberus.py", line 165, in validate
return self._validate(document, schema, update=update, context=context)
File "cerberus/cerberus.py", line 228, in _validate
self.allow_unknown})
File "cerberus/cerberus.py", line 118, in __init__
self.validate_schema(schema)
File "cerberus/cerberus.py", line 278, in validate_schema
errors.ERROR_UNKNOWN_TYPE % value)
cerberus.cerberus.SchemaError: unrecognized data-type 'foo'
The text was updated successfully, but these errors were encountered:
The Cerberus API allows custom validation properties and custom validation types to be added by creating a class that inherits from
cerberus.Validator
. It also allows validation rules to be supplied for arbitrary fields, via theallow_unknown
property. However, the schema for unknown properties cannot make use of custom validation properties and custom validation types.For example:
I would expect the call to
.validate()
to approve that document, but insteadI get a traceback:
The text was updated successfully, but these errors were encountered: