wharton / drf-excel

An XLSX spreadsheet renderer for Django REST Framework.
BSD 3-Clause "New" or "Revised" License
212 stars 40 forks source link

Should XLSXListField Support Nullable Values? #61

Open thomasmatecki opened 2 years ago

thomasmatecki commented 2 years ago

Currently XLSXListField does not behave very nicely if prepping a value of None. This field corresponds to DRF's ListField, which does support allow_null=True.

    def prep_value(self) -> Any:
>       if len(self.value) > 0 and isinstance(self.value[0], Iterable):
E       TypeError: object of type 'NoneType' has no len()

It seems as though this field should nicely handle null (None) values. Happy to open a PR if folks agree.

rptmat57 commented 2 years ago

That sounds like a good idea to me. It should definitely handle None and return '' in that case.