mixxorz / django-service-objects

Service objects for Django
MIT License
337 stars 29 forks source link

MultipleModelField and ListField don't allow empty lists #73

Open taobojlen opened 2 years ago

taobojlen commented 2 years ago

We've been using this library for a few weeks and we're really liking it so far -- thank you!

There's one thing that keeps tripping us up: the MultipleModelField and ListFields (and maybe others) fail their validation if you pass an empty list. This is counterintuitive -- an empty list is still a list! You can work around it by setting required=False on the field, but then there's an ambiguity around whether the field is [] or None.

Would you be open to a PR that changed this behaviour such that empty lists are allowed?

peterfarrell commented 1 year ago

It would likely break backwards compatibility if this behavior was changed. What about adding a new attribute called allow_empty which defaults to False (to maintain BC)?