divio / djangocms-rest-api

A REST API for django CMS
MIT License
51 stars 18 forks source link

Rendering serializers fails due to not explicitly setting Meta.fields or Meta.exclude for DRF>=3.5. #16

Open tjb346 opened 7 years ago

tjb346 commented 7 years ago

I am getting the following error using the plugin api with Django Rest Framework versions 3.5 or greater: Creating a ColumnSerializer without either the 'fields' attribute or the 'exclude' attribute has been deprecated since 3.3.0, and is now disallowed. Add an explicit fields = '__all__' to the ColumnSerializer serializer.

It seems like this is caused by the method modelserializer_factory not setting fields or exclude when the fields or exclude keyword arguments are left as None, as shown here:

    if fields is not None:
        meta_attrs['fields'] = fields
    if exclude is not None:
        meta_attrs['exclude'] = exclude

This can happen if serializer_class is not set for the plugin, or if it is not in the serializer_class_mapping. Maybe metaattrs['fields'] should default to '__all_\' if both fields and exclude are None?