diff --git a/graphene_django/rest_framework/mutation.py b/graphene_django/rest_framework/mutation.py index d9c695e..fdd6c10 100644 --- a/graphene_django/rest_framework/mutation.py +++ b/graphene_django/rest_framework/mutation.py @@ -124,7 +124,7 @@ class SerializerMutation(ClientIDMutation): kwargs = cls.get_serializer_kwargs(root, info, **input) serializer = cls._meta.serializer_class(**kwargs) - if serializer.is_valid(): + if serializer.is_valid(raise_exception=True): return cls.perform_mutate(serializer, info) else: errors = ErrorType.from_errors(serializer.errors) diff --git a/graphene_django/rest_framework/tests/test_mutation.py b/graphene_django/rest_framework/tests/test_mutation.py index 9d8b950..f8301d3 100644 --- a/graphene_django/rest_framework/tests/test_mutation.py +++ b/graphene_django/rest_framework/tests/test_mutation.py @@ -5,6 +5,7 @@ from rest_framework import serializers from graphene import Field, ResolveInfo from graphene.types.inputobjecttype import InputObjectType +from rest_framework.exceptions import ValidationError from ...settings import graphene_settings from ...types import DjangoObjectType @@ -204,20 +205,23 @@ def test_mutate_and_get_payload_error(): serializer_class = MySerializer # missing required fields - result = MyMutation.mutate_and_get_payload(None, mock_info(), **{}) - assert len(result.errors) > 0 + with raises(ValidationError): + result = MyMutation.mutate_and_get_payload(None, mock_info(), **{}) + assert len(result.errors) > 0 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 + with raises(ValidationError): + result = MyModelMutation.mutate_and_get_payload(None, mock_info(), **{}) + assert len(result.errors) > 0 def test_mutation_error_camelcased(): graphene_settings.CAMELCASE_ERRORS = True - result = MyModelMutation.mutate_and_get_payload(None, mock_info(), **{}) - assert result.errors[0].field == "coolName" + with raises(ValidationError): + result = MyModelMutation.mutate_and_get_payload(None, mock_info(), **{}) + assert result.errors[0].field == "coolName" graphene_settings.CAMELCASE_ERRORS = False