jazzband / jazzband/jsonmodels

Models in ListField are not validated when calling `.validate()`

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

Description

If we have a `ListField` with items of type `models.Base`, for example:

```python
from jsonmodels import models, fields

class Cat(models.Base):
name = fields.StringField(required=True)

class Person(models.Base):
pets = fields.ListField([Cat])
```

And we call `.validate()` on the model:
```python
person = Person(pets=[Cat()])
person.validate()
```
Then nothing will happen, but if we call `.to_struct()` on the model:
```python
person = Person(pets=[Cat()])
person.to_struct()
```
Then a `ValidationError` is raised:
```shell
>>> jsonmodels.errors.ValidationError: ("Error for field 'name'.", ValidationError('Field is required!'))
```

Is this working as intended or should the list call `.validate()` on its items if the item is an instance of a model?

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.