question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DjangoModelFormMutation getting "an invalid keyword argument for Mutation" error instead of model form errors

See original GitHub issue

When using DjangoModelFormMutation and getting a modelform error the mutation shows an invalid keyword argument for Mutation as shown below. I am supposed to get errors for the field name showing “This name has already been registered.” However I am getting graphql.error.located_error.GraphQLLocatedError: ‘name’ is an invalid keyword argument for CategoryMutation

# model
class Category(models.Model):
    name = models.CharField(max_length=10, unique=True,
                 error_messages={'unique':"This name has already been registered."})

    def __str__(self):
        return self.name

#model form
class CategoryForm(ModelForm):
    class Meta:
        model = Category
        exclude = []

# create category mutation
class CategoryMutation(DjangoModelFormMutation):
    category = graphene.Field(CategoryType)
    class Meta:
        form_class = CategoryForm

mutation:

mutation {
  categoryCreate(input: {name: "spices"}) {
    errors {
      field,
      messages
    }
  }
}

results when the name is not unique:

{
  "errors": [
    {
      "message": "'name' is an invalid keyword argument for CategoryMutation",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "categoryCreate"
      ]
    }
  ],
  "data": {
    "categoryCreate": null
  }
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
jkimbocommented, Apr 12, 2020
2reactions
ajatprabhacommented, Apr 6, 2020

There should be two things that should be changed IMO

  1. An assertion that return_field_name is set in Meta options to match a field name in mutation class https://github.com/graphql-python/graphene-django/blob/b84f61afab5922f7a330b2f09bdf540b40b44e86/graphene_django/forms/mutation.py#L165-L169
  2. form.data should be handled differently or should be removed altogether and the length of errors should be used to determine success/failure https://github.com/graphql-python/graphene-django/blob/b84f61afab5922f7a330b2f09bdf540b40b44e86/graphene_django/forms/mutation.py#L45-L50
Read more comments on GitHub >

github_iconTop Results From Across the Web

getting 'name' is an invalid keyword argument (using ...
i am using graphene and getting 'name' is an invalid keyword argument for GuestMutation error what is it related to? //models.py class ...
Read more >
Mutations - Graphene-Python
These errors have two fields: field , a string containing the name of the invalid form field, and messages , a list of...
Read more >
'creation_date' is an invalid keyword argument for this function
So I'm pretty new to Django and I'm playing around with forms/models, and I've run into an error that I think has to...
Read more >
Integration with Django forms - Graphene-Python
This argument should be a dict where the key is name and the value is a string. ModelFormMutation¶. ModelFormMutation will pull the fields...
Read more >
Forms So Painless a Baby Could Write 'em with Django's ...
Mutations and django-graphene's Model Form Mutations ... The form takes two keyword arguments, data and instance.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found