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.

Adding DjangoModelFormMutation to schema raises import error

See original GitHub issue

Hi there!

I try to use the awesome DjangoModelFormMutation but when I add the mutation to the schema I always get this error:

Could not import 'project.config.schema.schema' for Graphene setting 'SCHEMA'. AttributeError: 'NoneType' object has no attribute '_meta'.

Here’s my setup:

class Pet(models.Model):
    name = models.CharField()

class PetForm(forms.ModelForm):
    class Meta:
        model = Pet
        fields = ('name',)

class PetMutation(DjangoModelFormMutation):
    class Meta:
        form_class = PetForm

class PetMutations(graphene.ObjectType):
    pet = PetMutation.Field(description="Pets!")


class Mutation(PetMutations,
               graphene.ObjectType):
    pass

schema = graphene.Schema(query=Query, mutation=Mutation)

Any ideas what I might be doing wrong?

Thanks! Ron

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
GitRoncommented, Mar 27, 2019

Aaaaaaaaaaaaaaaaad I found the solution:

class PetCrudMutation(DjangoModelFormMutation):
    pet= graphene.Field(PetType)
    class Meta:
        form_class = PetForm

I’m going to add this to the documentation 😃

1reaction
zbyte64commented, Mar 26, 2019

django-graphene is trying to import your schema file and is encountering another error along the way. I would recommend doing a manage.py shell and attempt manually importing the schema. This way you can see the import error without other code eating the message.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding DjangoModelFormMutation to schema raises import ...
django-graphene is trying to import your schema file and is encountering another error along the way. I would recommend doing a manage.py shell...
Read more >
Mutations - Graphene-Python
DjangoModelFormMutation will pull the fields from a ModelForm . from graphene_django.forms.mutation import DjangoModelFormMutation class Pet( ...
Read more >
Graphene input error for Pydantic models with discriminator ...
I am writing GraphQL APIs and want to convert those pydantic models into graphene input objects. Below is my code. from graphene_pydantic import...
Read more >
Graphene Documentation - Read the Docs
We need to add a graphql URL to the urls.py of your Django project: For Django 2.2 and above: from django.urls import path....
Read more >
Importerror: No Module Named 'Cython' When Installing ...
Pip install fails with ImportError: No module named Cython. ... graphql-relay2.0.1 Adding DjangoModelFormMutation to schema raises import error hot 8.
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