Skip to content

Commit 5eb5559

Browse files
aubustoujnak
authored andcommitted
[Python 2] Add support for unicode field names
Check against six.string_types instead of str for python 2 compatibility
1 parent a361c52 commit 5eb5559

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

graphene_sqlalchemy/enums.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import six
12
from sqlalchemy.orm import ColumnProperty
23
from sqlalchemy.types import Enum as SQLAlchemyEnumType
34

@@ -62,7 +63,7 @@ def enum_for_field(obj_type, field_name):
6263
if not isinstance(obj_type, type) or not issubclass(obj_type, SQLAlchemyObjectType):
6364
raise TypeError(
6465
"Expected SQLAlchemyObjectType, but got: {!r}".format(obj_type))
65-
if not field_name or not isinstance(field_name, str):
66+
if not field_name or not isinstance(field_name, six.string_types):
6667
raise TypeError(
6768
"Expected a field name, but got: {!r}".format(field_name))
6869
registry = obj_type._meta.registry

graphene_sqlalchemy/fields.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import warnings
22
from functools import partial
33

4+
import six
45
from promise import Promise, is_thenable
56
from sqlalchemy.orm.query import Query
67

@@ -35,7 +36,7 @@ def model(self):
3536
def get_query(cls, model, info, sort=None, **args):
3637
query = get_query(model, info.context)
3738
if sort is not None:
38-
if isinstance(sort, str):
39+
if isinstance(sort, six.string_types):
3940
query = query.order_by(sort.value)
4041
else:
4142
query = query.order_by(*(col.value for col in sort))

graphene_sqlalchemy/registry.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from collections import defaultdict
22

3+
import six
34
from sqlalchemy.types import Enum as SQLAlchemyEnumType
45

56
from graphene import Enum
@@ -42,7 +43,7 @@ def register_orm_field(self, obj_type, field_name, orm_field):
4243
raise TypeError(
4344
"Expected SQLAlchemyObjectType, but got: {!r}".format(obj_type)
4445
)
45-
if not field_name or not isinstance(field_name, str):
46+
if not field_name or not isinstance(field_name, six.string_types):
4647
raise TypeError("Expected a field name, but got: {!r}".format(field_name))
4748
self._registry_orm_fields[obj_type][field_name] = orm_field
4849

0 commit comments

Comments
 (0)