jazzband / jsonmodels

jsonmodels is library to make it easier for you to deal with structures that are converted to, or read from JSON.
http://jsonmodels.readthedocs.org/en/latest/
BSD 3-Clause "New" or "Revised" License
334 stars 51 forks source link

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

Open paulopaixaoamaral opened 4 years ago

paulopaixaoamaral commented 4 years ago

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

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:

person = Person(pets=[Cat()])
person.validate()

Then nothing will happen, but if we call .to_struct() on the model:

person = Person(pets=[Cat()])
person.to_struct()

Then a ValidationError is raised:

>>> 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?