Skip to content

Commit ee8a28b

Browse files
committed
Change if condition
ChoiceType no longer relies on EnumMeta but instead it exposes a ``type_impl`` field that we can leverage to decide whether the internal ``choices`` is a tuple of enum members or a tuple of tuples (pairs)
1 parent 52c718d commit ee8a28b

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

graphene_sqlalchemy/converter.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from enum import EnumMeta
21
from functools import singledispatch
32

43
from sqlalchemy import types
@@ -21,6 +20,11 @@
2120
except ImportError:
2221
ChoiceType = JSONType = ScalarListType = TSVectorType = object
2322

23+
try:
24+
from sqlalchemy_utils.types.choice import EnumTypeImpl
25+
except ImportError:
26+
EnumTypeImpl = object
27+
2428

2529
is_selectin_available = getattr(strategies, 'SelectInLoader', None)
2630

@@ -222,7 +226,7 @@ def convert_enum_to_enum(type, column, registry=None):
222226
@convert_sqlalchemy_type.register(ChoiceType)
223227
def convert_choice_to_enum(type, column, registry=None):
224228
name = "{}_{}".format(column.table.name, column.name).upper()
225-
if isinstance(type.choices, EnumMeta):
229+
if isinstance(type.type_impl, EnumTypeImpl):
226230
# type.choices may be Enum/IntEnum, in ChoiceType both presented as EnumMeta
227231
# do not use from_enum here because we can have more than one enum column in table
228232
return Enum(name, list((v.name, v.value) for v in type.choices))

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ max-line-length = 120
99
no_lines_before=FIRSTPARTY
1010
known_graphene=graphene,graphql_relay,flask_graphql,graphql_server,sphinx_graphene_theme
1111
known_first_party=graphene_sqlalchemy
12-
known_third_party=app,database,flask,graphql,models,nameko,pkg_resources,promise,pytest,schema,setuptools,sqlalchemy,sqlalchemy_utils
12+
known_third_party=app,database,flask,models,nameko,pkg_resources,promise,pytest,schema,setuptools,sqlalchemy,sqlalchemy_utils
1313
sections=FUTURE,STDLIB,THIRDPARTY,GRAPHENE,FIRSTPARTY,LOCALFOLDER
1414
skip_glob=examples/nameko_sqlalchemy
1515

0 commit comments

Comments
 (0)