jazzband / jazzband/jsonmodels

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

Open
#123 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
343
Forks
50
PR merge metrics
No merged PRs in 30d

Description

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

```py
>>> 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.