[Patchew-devel] [PATCH v2] serializer: Add custom serialzer for recipients and sender

Paolo Bonzini pbonzini at redhat.com
Fri May 4 07:32:25 UTC 2018



----- Original Message -----
> From: "Shubham Jain" <shubhamjain7495 at gmail.com>
> To: "Paolo Bonzini" <pbonzini at redhat.com>
> Cc: patchew-devel at redhat.com
> Sent: Friday, May 4, 2018 8:47:44 AM
> Subject: Re: [Patchew-devel] [PATCH v2] serializer: Add custom serialzer for recipients and sender
> 
> I've found the error. Apparently In BaseMessageSerializer, sender and
> recipient are in the form of  OrderedDict([('name', 'Andrey Smirnov'),
> ('address', 'andrew.smirnov at gmail.com')]) instead of ['Andrey Smirnov','
> andrew.smirnov at gmail.com']. I'm not sure what is happening here. Is create
> of AddressSerializer not getting called?

I guess this is the "nested writable serializer" issue, and then you
have to call "create" yourself.  Following the example in the DRF
manual, it would be something like

    def create(self, validated_data):
        validated_data['sender'] = self.sender.create(**validated_data['sender'])
        ... same for recipients ...
        # Override get_serializer_context in ProjectMessagesViewSetMixin,
        # so that the project is passed down to the serializer
        # (see https://stackoverflow.com/questions/31038742/)
        # The new create method on MessageManager (as discussed on IRC)
        # saves the mbox and creates the object
        return Message.objects.create(project=self.context['project'],
                                      **validated_data)

Which of the tasks in "Convert `import` to REST style POST"
(https://github.com/patchew-project/patchew/issues/75) are you working
on now?

Thanks,

Paolo




More information about the Patchew-devel mailing list