Skip to content

Enum ChoiceType column results in error #196

@thejcannon

Description

@thejcannon

Howdy folks!

The following code produces TypeError: 'MyEnum' object is not iterable, but should work. Note that this is also involves package sqlalchemy_utils

from enum import Enum

class MyEnum(Enum):
   foo = 1
   bar = 2

class MyModel(Base):
    id = Column(sa.Integer, primary_key=True)
    name = Column(sa.Unicode(255))
    type = Column(ChoiceType(MyEnum, impl=Integer()))

class MyObject(SQLAlchemyObjectType):
    class Meta:
        model = MyModel

Activity

added 2 commits that reference this issue on Apr 1, 2019
ff2089e
ea62496
Nabellaleen

Nabellaleen commented on Apr 1, 2019

@Nabellaleen
Collaborator

Hi !

Is it really a bug ?

The graphene documentation suggest to use graphene.Enum in your schema and, if you already have a defined enum, to use graphene.Enum.from_enum(AlreadyExistingPyEnum)

source: https://docs.graphene-python.org/en/latest/types/enums/

thejcannon

thejcannon commented on Apr 1, 2019

@thejcannon
Author

Sure, but that defeats the automagical nature of using SQLAlchemyObjectType along with model = MyModel 😄. Part of the beauty of this library is that I don't have to specify the Schema fields, because they are deduced from the SQLAlchemy model.

There's also the fact that using sqlalchemy.Enum(MyEnum) works but sqlalchemy_utils.ChoiceType(MyEnum) doesn't 😦.

squarewave24

squarewave24 commented on May 28, 2020

@squarewave24

as things stand now, is it not possible to use field = Column(ChoiceType(my_enum))
along with SQLAlchemyObjectType auto models?

is there a workaround ?

thejcannon

thejcannon commented on May 28, 2020

@thejcannon
Author

Unfortunately I'm no longer on the project that was using this code, so I can't say.

kurtwiersma

kurtwiersma commented on Oct 29, 2021

@kurtwiersma

We were able to use a ChoiceType with graphene-sqlalchemy 2.3.0 under Python 3.8 but got this error when we upgraded to Python 3.9. I was able to figure out a fix for it by updating one line in the graphene-sqlalchemy library. If you like I can submit a PR and see if passes review and doesn't break anything else.

erikwrede

erikwrede commented on Aug 12, 2022

@erikwrede
Member

@kurtwiersma if you're still up for that, feel free to go ahead. It's probably best to create a new branch for the old release. Would appreciate the effort!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @squarewave24@Nabellaleen@thejcannon@erikwrede@kurtwiersma

      Issue actions

        Enum ChoiceType column results in error · Issue #196 · graphql-python/graphene-sqlalchemy