Skip to content

Commit

Permalink
Fix broken form.save() call in DjangoFormMutation.perform_mutate (#1155)
Browse files Browse the repository at this point in the history
Django's plain (non-model) forms don't have the `save` method, so
calling this would just result in an `AttributeError` before this
change.

Resolves #1152
  • Loading branch information
ruohola committed Apr 11, 2021
1 parent 26a851a commit 608af57
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion graphene_django/forms/mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ def __init_subclass_with_meta__(

@classmethod
def perform_mutate(cls, form, info):
form.save()
if hasattr(form, "save"):
# `save` method won't exist on plain Django forms, but this mutation can
# in theory be used with `ModelForm`s as well and we do want to save them.
form.save()
return cls(errors=[], **form.cleaned_data)


Expand Down

0 comments on commit 608af57

Please sign in to comment.