From e33a6002bfcf411210f52d5a1bce6c3919da1bce Mon Sep 17 00:00:00 2001 From: B4rtware <34386047+B4rtware@users.noreply.github.com> Date: Wed, 8 Jan 2020 13:35:38 +0100 Subject: [PATCH] fix datetime type does get converted to a string to_representation will convert the datetime field into a string representation. However the to_representation on the method field will only call its underlying method. --- graphene_django/rest_framework/mutation.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/graphene_django/rest_framework/mutation.py b/graphene_django/rest_framework/mutation.py index 3009c06..f9b074d 100644 --- a/graphene_django/rest_framework/mutation.py +++ b/graphene_django/rest_framework/mutation.py @@ -137,5 +137,13 @@ class SerializerMutation(ClientIDMutation): @classmethod def perform_mutate(cls, serializer, info): obj = serializer.save() - kwargs = serializer.to_representation(obj) + + kwargs = {} + for f, field in serializer.fields.items(): + if not field.write_only: + if isinstance(field, serializers.SerializerMethodField): + kwargs[f] = field.to_representation(obj) + else: + kwargs[f] = field.get_attribute(obj) + return cls(errors=None, **kwargs)