graphql-python / graphql-python/graphene-django
DjangoModelFormMutation missing result with snake_case field name
- Dominant language
- Python
- Stars
- 4.4k
- Forks
- 760
- PR merge metrics
- No merged PRs in 30d
Description
**Note: for support questions, please use stackoverflow**. This repository's issues are reserved for feature requests and bug reports.
* **What is the current behavior?**
The resulting object is missing in the mutation result when the field name has a snake case.
Example:
```python
class HouseWallForm(forms.ModelForm):
class Meta:
model = HouseWall
fields = ("title", "color", "width", "height")
class HouseWallNode(DjangoObjectType):
class Meta:
model = HouseWall
class CreateHouseWall(DjangoModelFormMutation):
house_wall = graphene.Field(HouseWallNode)
class Meta:
form_class = HouseWallForm
convert_choices_to_enum = True
class Mutation(graphene.ObjectType):
create_house_wall = CreateHouseWall.Field()
```
Running following mutation via graphql (with input variables):
```gql
mutation ($wall: CreateHouseWallInput!) {
createHouseWall (input: $wall) {
errors {field, messages},
houseWall {title, color, width, height}
}
}
```
Gives the following result:
```json
{
"data": {
"createHouseWall": {
"errors": [],
"houseWall": null
}
}
}
```
* **What is the expected behavior?**
```json
{
"data": {
"createHouseWall": {
"errors": [],
"houseWall": {
"title": "test-title",
"color": "red",
"height": 1,
"width": 2,
}
}
}
}
```
* **Please tell us about your environment:**
- Version: 2.15.0
- Platform: Linux (Docker)
* **Other information** (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow)
However - there is a workaround - add `return_field_name` to the `Meta` class:
```python
class CreateHouseWall(DjangoModelFormMutation):
house_wall = graphene.Field(HouseWallNode)
class Meta:
form_class = HouseWallForm
convert_choices_to_enum = True
return_field_name = 'house_wall'
```
I suspect it has something to do with the `auto_camelcase` feature. During debugging I saw some `result` variable containing a value for `house_wall` (`None`) and a value for `houseWall`(the expected result).
Contributor guide
Assessment
This issue has not been assessed yet.