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

Model validation should return the list of errors instead of the encountered error #123

Open
sergray opened this issue Jun 26, 2018 · 0 comments

Comments

@sergray
Copy link

sergray commented Jun 26, 2018

Current implementation of validation raises the jsonmodels.errors.ValidationError as soon as the first error is encountered.

>>> from jsonmodels import models, fields, validators
>>> class Person(models.Base):
...    name = fields.StringField(required=True, validators=validators.Length(1))
...    age = fields.IntField(required=True, validators=[validators.Min(14)])
... 
>>> p = Person()
>>> p.validate()
Traceback (most recent call last):
...
jsonmodels.errors.ValidationError: ("Error for field 'age'.", ValidationError('Field is required!',))    

That means there's no way to get an overview of all validation errors for particular model, which is essential for complex data models.

It would be great to have complete model validation errors, with complete list of the errors per each field. In above example, that could be

jsonmodels.errors.ValidationError: {'name': ['Field is required'], 'age': ['Field is required']}

That should work for embedded fields as well.

It is an open question, whether all validator for particular field should be executed or if inclusion of the first validation error for particular field is enough.

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

1 participant