graphql-python / graphql-python/graphene-django

DjangoModelFormMutation raising AttributeError on DjangoObjectTypeOptions

Open
#913 1 comment 0 reactions 0 assignees View on GitHub
🐛bug
Dominant language
Python
Stars
4.4k
Forks
760
PR merge metrics
No merged PRs in 30d

Description

The example from the docs should allow you to reproduce it. The error is raised when running `Run `python manage.py runserver``

```
from graphene_django.forms.mutation import DjangoModelFormMutation

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

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

# This will get returned when the mutation completes successfully
class PetType(DjangoObjectType):
class Meta:
model = Pet

class PetMutation(DjangoModelFormMutation):
pet = Field(PetType)

class Meta:
form_class = PetForm
```

Here's the relevant part of the stacktrace:

```
File "/home/Projects/foo/schema/foo.py", line 126, in
class FooForm(forms.ModelForm):
File "/home/Projects/.local/share/virtualenvs/Dr4iZ/lib/python3.8/site-packages/django/forms/models.py", line 252, in __new__
fields = fields_for_model(
File "/home/Projects/.local/share/virtualenvs/Dr4iZ/lib/python3.8/site-packages/django/forms/models.py", line 144, in fields_for_model
sortable_private_fields = [f for f in opts.private_fields if isinstance(f, ModelField)]
AttributeError: 'DjangoObjectTypeOptions' object has no attribute 'private_fields'
```

Platform:
```
Ubuntu 18.04.4
Python 3.8.2

Django==3.0.4
django-debug-toolbar==2.2
django-graphiql-debug-toolbar==0.1.4
django-graphql-jwt==0.3.0
graphene==2.1.8
graphene-django==2.9.0
graphql-core==2.3.1
graphql-relay==2.0.1
```

I switched over to relay mutations so this issue is more for documentation. I would guess that this broke with Django 3, but it's hard to tell since there aren't any automated tests for this functionality.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.