Skip to content

Commit adb0947

Browse files
committed
Apply camel case converter to field names in DRF errors
1 parent f76f38e commit adb0947

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

graphene_django/rest_framework/mutation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from graphene.types.mutation import MutationOptions
88
from graphene.relay.mutation import ClientIDMutation
99
from graphene.types.objecttype import yank_fields_from_attrs
10+
from graphene.utils.str_converters import to_camel_case
1011

1112
from .serializer_converter import convert_serializer_field
1213
from .types import ErrorType
@@ -126,7 +127,7 @@ def mutate_and_get_payload(cls, root, info, **input):
126127
return cls.perform_mutate(serializer, info)
127128
else:
128129
errors = [
129-
ErrorType(field=key, messages=value)
130+
ErrorType(field=to_camel_case(key), messages=value)
130131
for key, value in serializer.errors.items()
131132
]
132133

graphene_django/rest_framework/tests/test_mutation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ def test_model_mutate_and_get_payload_error():
166166
# missing required fields
167167
result = MyModelMutation.mutate_and_get_payload(None, mock_info(), **{})
168168
assert len(result.errors) > 0
169+
assert result.errors[0].field == 'coolName'
169170

170171

171172
def test_invalid_serializer_operations():

0 commit comments

Comments
 (0)