From 942bb6c7e017a0778de95bdc7b837c7573d3e352 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Sun, 28 Oct 2018 19:58:40 +0000 Subject: [PATCH] Return correct errors --- graphene_django/rest_framework/mutation.py | 8 +++----- graphene_django/rest_framework/tests/test_mutation.py | 5 +++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/graphene_django/rest_framework/mutation.py b/graphene_django/rest_framework/mutation.py index 0a88ec2..1869d0d 100644 --- a/graphene_django/rest_framework/mutation.py +++ b/graphene_django/rest_framework/mutation.py @@ -140,12 +140,10 @@ class SerializerMutation(ClientIDMutation): if serializer.is_valid(): return cls.perform_mutate(serializer, info) else: - errors = [ - ErrorType(field=key, messages=value) - for key, value in serializer.errors.items() - ] + # TODO: make sure that we have the correct value for + # non field errors - return cls(errors=errors) + return cls(errors=cls.Errors(**serializer.errors)) @classmethod def perform_mutate(cls, serializer, info): diff --git a/graphene_django/rest_framework/tests/test_mutation.py b/graphene_django/rest_framework/tests/test_mutation.py index 5afe3cc..10d5828 100644 --- a/graphene_django/rest_framework/tests/test_mutation.py +++ b/graphene_django/rest_framework/tests/test_mutation.py @@ -159,13 +159,14 @@ def test_mutate_and_get_payload_error(): # missing required fields result = MyMutation.mutate_and_get_payload(None, mock_info(), **{}) - assert len(result.errors) > 0 + assert result.errors.text[0] == "This field is required." + assert result.errors.model[0] == "This field is required." def test_model_mutate_and_get_payload_error(): # missing required fields result = MyModelMutation.mutate_and_get_payload(None, mock_info(), **{}) - assert len(result.errors) > 0 + assert result.errors.cool_name[0] == "This field is required." def test_invalid_serializer_operations():