Skip to content

Commit

Permalink
[Python 2] Add support for unicode field names
Browse files Browse the repository at this point in the history
Check against six.string_types instead of str for python 2 compatibility
  • Loading branch information
aubustou authored and jnak committed Aug 28, 2019
1 parent a361c52 commit 5eb5559
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion graphene_sqlalchemy/enums.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import six
from sqlalchemy.orm import ColumnProperty
from sqlalchemy.types import Enum as SQLAlchemyEnumType

Expand Down Expand Up @@ -62,7 +63,7 @@ def enum_for_field(obj_type, field_name):
if not isinstance(obj_type, type) or not issubclass(obj_type, SQLAlchemyObjectType):
raise TypeError(
"Expected SQLAlchemyObjectType, but got: {!r}".format(obj_type))
if not field_name or not isinstance(field_name, str):
if not field_name or not isinstance(field_name, six.string_types):
raise TypeError(
"Expected a field name, but got: {!r}".format(field_name))
registry = obj_type._meta.registry
Expand Down
3 changes: 2 additions & 1 deletion graphene_sqlalchemy/fields.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import warnings
from functools import partial

import six
from promise import Promise, is_thenable
from sqlalchemy.orm.query import Query

Expand Down Expand Up @@ -35,7 +36,7 @@ def model(self):
def get_query(cls, model, info, sort=None, **args):
query = get_query(model, info.context)
if sort is not None:
if isinstance(sort, str):
if isinstance(sort, six.string_types):
query = query.order_by(sort.value)
else:
query = query.order_by(*(col.value for col in sort))
Expand Down
3 changes: 2 additions & 1 deletion graphene_sqlalchemy/registry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections import defaultdict

import six
from sqlalchemy.types import Enum as SQLAlchemyEnumType

from graphene import Enum
Expand Down Expand Up @@ -42,7 +43,7 @@ def register_orm_field(self, obj_type, field_name, orm_field):
raise TypeError(
"Expected SQLAlchemyObjectType, but got: {!r}".format(obj_type)
)
if not field_name or not isinstance(field_name, str):
if not field_name or not isinstance(field_name, six.string_types):
raise TypeError("Expected a field name, but got: {!r}".format(field_name))
self._registry_orm_fields[obj_type][field_name] = orm_field

Expand Down

0 comments on commit 5eb5559

Please sign in to comment.