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

allow_unknown does not respect custom validators #66

Closed
OptiverTimAll opened this issue Jan 30, 2015 · 1 comment
Closed

allow_unknown does not respect custom validators #66

OptiverTimAll opened this issue Jan 30, 2015 · 1 comment

Comments

@OptiverTimAll
Copy link

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'
@nicolaiarocci
Copy link
Member

thanks should be fixed now.

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

2 participants