diff --git a/graphene_django/forms/converter.py b/graphene_django/forms/converter.py index 220edc4..9d87811 100644 --- a/graphene_django/forms/converter.py +++ b/graphene_django/forms/converter.py @@ -16,21 +16,6 @@ except AttributeError: singledispatch = import_single_dispatch() -def convert_form_to_input_type(form_class): - form = form_class() - - items = { - name: convert_form_field(field) - for name, field in form.fields.items() - } - - return type( - '{}Input'.format(form.__class__.__name__), - (graphene.InputObjectType, ), - items - ) - - @singledispatch def convert_form_field(field): raise ImproperlyConfigured( diff --git a/graphene_django/forms/mutation.py b/graphene_django/forms/mutation.py index bbe5f80..49fabb8 100644 --- a/graphene_django/forms/mutation.py +++ b/graphene_django/forms/mutation.py @@ -83,7 +83,7 @@ class FormMutation(BaseFormMutation): @classmethod def perform_mutate(cls, form, info): form.save() - return cls(errors=None) + return cls(errors=[]) class ModelFormMutationOptions(FormMutationOptions): @@ -138,4 +138,4 @@ class ModelFormMutation(BaseFormMutation): def perform_mutate(cls, form, info): obj = form.save() kwargs = {cls._meta.return_field_name: obj} - return cls(errors=None, **kwargs) + return cls(errors=[], **kwargs) diff --git a/graphene_django/forms/tests/test_mutation.py b/graphene_django/forms/tests/test_mutation.py index 5f1ef4a..084b8b0 100644 --- a/graphene_django/forms/tests/test_mutation.py +++ b/graphene_django/forms/tests/test_mutation.py @@ -68,8 +68,23 @@ class ModelFormMutationTests(TestCase): class Meta: form_class = PetForm - PetMutation.mutate_and_get_payload(None, None, name='Fluffy') + result = PetMutation.mutate_and_get_payload(None, None, name='Fluffy') self.assertEqual(Pet.objects.count(), 1) pet = Pet.objects.get() self.assertEqual(pet.name, 'Fluffy') + self.assertEqual(result.errors, []) + + def test_model_form_mutation_mutate_invalid_form(self): + class PetMutation(ModelFormMutation): + class Meta: + form_class = PetForm + + result = PetMutation.mutate_and_get_payload(None, None) + + # A pet was not created + self.assertEqual(Pet.objects.count(), 0) + + self.assertEqual(len(result.errors), 1) + self.assertEqual(result.errors[0].field, 'name') + self.assertEqual(result.errors[0].messages, ['This field is required.'])