Creating a ModelSerializer 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 NestedSerializer serializer.
Closed this issue · 12 comments
I just updated django-rest-framework
to 3.5.*
, and i got this error
Creating a ModelSerializer 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 NestedSerializer serializer.
my serializers defines as bellow:
class FlightResponseSerializer(mongo_serializer.EmbeddedDocumentSerializer):
class Meta:
model = models.FlightModelList
exclude = ('request_id', 'application', 'provider')
depth = 3
class SearchGetOutputSerializer(mongo_serializer.EmbeddedDocumentSerializer):
request_id = serializers.CharField()
available_flights = FlightResponseSerializer(many=True)
class Meta:
model = models.FlightResponse
fields = ('request_id', 'last_seed', 'available_flights')
Hi, @amirasaran!
You shouldn't create two serializers manually. Instead, do it as follows:
class FlightResponse(mongoengine.Document):
...
class SearchGetOutput(mongoengine.Document):
request_id = mongoengine.StringField(required=True, primary_key=True)
available_flights = EmbeddedDocumenListField(FlightResponse)
class SearchGetOutputSerializer(mongo_serializer.DocumentSerializer):
class Meta:
model = models.SearchGetOutput
depth = 3
I mean, in DRF-ME you don't create nested serializers for EmbeddedDocuments manually. You just declare EmbeddedDocumentField
or EmbeddedDocumentListField
on your Document model and create top-level serializer only for that top-level Document. DRF-ME will create all the EmbeddedDocumentSerializers automatically. See this, if you need an example: medium.com/@vasjaforutube/django-mongodb-django-rest-framework-mongoengine-ee4eb5857b9a
Thanks @BurkovBA
I got your concept, but DRF-ME should support the latest version of DRF.
do you have any idea about this ?
@amirasaran
Yeah, you're right about the release. There's a lot of unreleased changes in DRF-ME, which are compatible with DRF 3.3.3, so I'll make a release for DRF 3.3.3 first and then look into new features in DRFs 3.4 and 3.5.
I create a pull request
@chepe4pi Thanks
when we can use this changes via pip
?
@amirasaran I'm not sure about it...
@BurkovBA Can you answer?
@chepe4pi @amirasaran I have maintainer permissions here at github, but to create a PyPI release, I need Umut Bozkurt to give me maintainer permissions at PyPI. I've sent a request to him, currently waiting for him to answer. After that, hopefully, I'll make a release on the next weekend.
@chepe4pi @amirasaran Umut gave me maintainer permissions at PyPI. I hope, I'll release 3.3.1 at this weekend.
Released 3.3.1 at least for python2.7.
for me it worked as the error is saying fields .....
class FlightResponseSerializer(mongo_serializer.EmbeddedDocumentSerializer):
class Meta:
model = models.FlightModelList
exclude = ('request_id', 'application', 'provider')
depth = 3
fields = 'all' #This should work :)
I'm facing with this error, who can help me now? thanks for your helping.
Hayzz 2 minutes I resolved it =>add
fields = '_ _ all _ _'
here (that's very simply)