Serializer object has no attribute '_writable_fields'

604 views Asked by At

I have started writing an app in django with mongodb (my first time). But I'm getting this error related to my DRF-mongoengine serializer. The error reads:

AttributeError: 'UserSerializer' object has no attribute '_writable_fields'

Full Traceback is as follows:

Traceback (most recent call last):
web_1  |   File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response
web_1  |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
web_1  |   File "/usr/local/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
web_1  |     return view_func(*args, **kwargs)
web_1  |   File "/usr/local/lib/python2.7/site-packages/rest_framework/viewsets.py", line 85, in view
web_1  |     return self.dispatch(request, *args, **kwargs)
web_1  |   File "/usr/local/lib/python2.7/site-packages/rest_framework/views.py", line 407, in dispatch
web_1  |     response = self.handle_exception(exc)
web_1  |   File "/usr/local/lib/python2.7/site-packages/rest_framework/views.py", line 404, in dispatch
web_1  |     response = handler(request, *args, **kwargs)
web_1  |   File "/usr/local/lib/python2.7/site-packages/rest_framework/mixins.py", line 20, in create
web_1  |     serializer.is_valid(raise_exception=True)
web_1  |   File "/usr/local/lib/python2.7/site-packages/rest_framework/serializers.py", line 186, in is_valid
web_1  |     self._validated_data = self.run_validation(self.initial_data)
web_1  |   File "/usr/local/lib/python2.7/site-packages/rest_framework/serializers.py", line 364, in run_validation
web_1  |     value = self.to_internal_value(data)
web_1  |   File "/usr/local/lib/python2.7/site-packages/rest_framework_mongoengine/serializers.py", line 197, in to_internal_value
web_1  |     for field in self._writable_fields:
web_1  | AttributeError: 'UserSerializer' object has no attribute '_writable_fields'

This seems to be some problem with the DRF-mongoengine version because when I was using 3.3.0, I had an error about no no attribute named "get_field_names". To resolve that, I moved to 3.3.1 which is the lastest version and I started getting this one. My requirements.txt file is:

blinker == 1.1
Django==1.8.0
django-rest-framework-mongoengine==3.3.1
gunicorn==19.6.0
django-admin-generator==2.0.0
pymongo==2.8
mongoengine==0.9.0
djangorestframework==3.0.4

And my serializers.py file is:

from rest_framework_mongoengine import serializers

from api.models import User

class UserSerializer(serializers.DocumentSerializer):
    class Meta:
        model = User
        fields = '__all__'

My models are:

from mongoengine import *


class User(Document):
    name = StringField(max_length=50, required=True)
    email = EmailField(max_length=254, required=True)
    password = StringField(max_length=100, required=True)
    role = StringField(max_length=16, default='basic', required=True)

    def __unicode__(self):
        return self.name, self.email

Any idea as to what happens to be the problem?

0

There are 0 answers