umutbozkurt / django-rest-framework-mongoengine

Mongoengine support for Django Rest Framework
MIT License
616 stars 167 forks source link

Serializer Field: `default=0` gets ignored #282

Open acu192 opened 3 years ago

acu192 commented 3 years ago

Because of this line: https://github.com/umutbozkurt/django-rest-framework-mongoengine/blob/2ab11b39428f5c3ecc0712885884e3c325528e66/rest_framework_mongoengine/utils.py#L147

If default is "falsy" (like if you do default=0 on an IntField) then the default is ignored.

acu192 commented 3 years ago

A workaround is to do default=lambda: 0 on your ME fields, instead of just the simple default=0.