Skip to content

graphene3: enum doesn't resolve to value #1277

Closed
@Speedy1991

Description

@Speedy1991

Using enums as inputFields leads to errors

SalutationEnum = graphene.Enum('SalutationEnum', [('Man', 0), ('Woman', 1)])

class MyModel(Model):
  salutation = models.IntegerField()

class SomeInput(graphene.InputObjectType):
    salutation = SalutationEnum(required=True)

class MyMutation(graphene.Mutation):
    ...
    class Arguments:
        input = SomeInput(required=True)
    ...

    mutate(self, info, input):
        ...
        myModel.salutation = input.salutation
        myModel.save()

leads to

"message": "Field 'salutation' expected a number but got <SalutationEnum.Man: 0>.",

I think the problem is, that SalutationEnum is not resolved to its value (this worked in graphene 2.x) but resolved to a SalutationEnum

salutation: SalutationEnum{
  name: 'Man'
  value: 0
}

This code would work:

 myModel.salutation = input.salutation.value
 myModel.save()

But I don't think it is intended to call value on each enum?

Edit:
Just found #1151 - looks like this is intended??

graphene: 3.0.0b5

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions