Skip to content

Commit 5117e53

Browse files
authored
add support for enums in sqlalchemy ChoiceType
1 parent c89cf80 commit 5117e53

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

graphene_sqlalchemy/converter.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
String)
88
from graphene.types.json import JSONString
99

10+
from enum import EnumMeta
1011
from .enums import enum_for_sa_enum
1112
from .registry import get_global_registry
1213

@@ -167,7 +168,12 @@ def convert_enum_to_enum(type, column, registry=None):
167168
@convert_sqlalchemy_type.register(ChoiceType)
168169
def convert_choice_to_enum(type, column, registry=None):
169170
name = "{}_{}".format(column.table.name, column.name).upper()
170-
return Enum(name, type.choices)
171+
if isinstance(type.choices, EnumMeta):
172+
# type.choices may be Enum/IntEnum, in ChoiceType both presented as EnumMeta
173+
# do not use from_enum here because we can have more than one enum column in table
174+
return Enum(name, list((v.name, v.value) for v in type.choices))
175+
else:
176+
return Enum(name, type.choices)
171177

172178

173179
@convert_sqlalchemy_type.register(ScalarListType)

0 commit comments

Comments
 (0)