-
Notifications
You must be signed in to change notification settings - Fork 227
Open
Labels
Description
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
squarewave24
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
Fix graphql-python#196 - handle ChoiceType initialized with Enum
Fix graphql-python#196 - handle ChoiceType initialized with Enum
Nabellaleen commentedon Apr 1, 2019
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 usegraphene.Enum.from_enum(AlreadyExistingPyEnum)
source: https://docs.graphene-python.org/en/latest/types/enums/
thejcannon commentedon Apr 1, 2019
Sure, but that defeats the automagical nature of using
SQLAlchemyObjectType
along withmodel = 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 butsqlalchemy_utils.ChoiceType(MyEnum)
doesn't 😦.squarewave24 commentedon May 28, 2020
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 commentedon May 28, 2020
Unfortunately I'm no longer on the project that was using this code, so I can't say.
kurtwiersma commentedon Oct 29, 2021
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 commentedon Aug 12, 2022
@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!