Skip to content

Commit dac341a

Browse files
committed
Fix deprecation warnings
1 parent 9a0f740 commit dac341a

File tree

3 files changed

+35
-32
lines changed

3 files changed

+35
-32
lines changed

Diff for: graphene_sqlalchemy/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from .fields import SQLAlchemyConnectionField
33
from .utils import get_query, get_session
44

5-
__version__ = "2.2.0"
5+
__version__ = "2.2.1"
66

77
__all__ = [
88
"__version__",

Diff for: graphene_sqlalchemy/fields.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import logging
1+
import warnings
22
from functools import partial
33

44
from promise import Promise, is_thenable
@@ -10,8 +10,6 @@
1010

1111
from .utils import get_query
1212

13-
log = logging.getLogger()
14-
1513

1614
class UnsortedSQLAlchemyConnectionField(ConnectionField):
1715
@property
@@ -100,34 +98,37 @@ def __init__(self, type, *args, **kwargs):
10098
def default_connection_field_factory(relationship, registry, **field_kwargs):
10199
model = relationship.mapper.entity
102100
model_type = registry.get_type_for_model(model)
103-
return createConnectionField(model_type, **field_kwargs)
101+
return __connectionFactory(model_type, **field_kwargs)
104102

105103

106104
# TODO Remove in next major version
107105
__connectionFactory = UnsortedSQLAlchemyConnectionField
108106

109107

110108
def createConnectionField(_type, **field_kwargs):
111-
log.warning(
109+
warnings.warn(
112110
'createConnectionField is deprecated and will be removed in the next '
113-
'major version. Use SQLAlchemyObjectType.Meta.connection_field_factory instead.'
111+
'major version. Use SQLAlchemyObjectType.Meta.connection_field_factory instead.',
112+
DeprecationWarning,
114113
)
115114
return __connectionFactory(_type, **field_kwargs)
116115

117116

118117
def registerConnectionFieldFactory(factoryMethod):
119-
log.warning(
118+
warnings.warn(
120119
'registerConnectionFieldFactory is deprecated and will be removed in the next '
121-
'major version. Use SQLAlchemyObjectType.Meta.connection_field_factory instead.'
120+
'major version. Use SQLAlchemyObjectType.Meta.connection_field_factory instead.',
121+
DeprecationWarning,
122122
)
123123
global __connectionFactory
124124
__connectionFactory = factoryMethod
125125

126126

127127
def unregisterConnectionFieldFactory():
128-
log.warning(
128+
warnings.warn(
129129
'registerConnectionFieldFactory is deprecated and will be removed in the next '
130-
'major version. Use SQLAlchemyObjectType.Meta.connection_field_factory instead.'
130+
'major version. Use SQLAlchemyObjectType.Meta.connection_field_factory instead.',
131+
DeprecationWarning,
131132
)
132133
global __connectionFactory
133134
__connectionFactory = UnsortedSQLAlchemyConnectionField

Diff for: graphene_sqlalchemy/tests/test_types.py

+23-21
Original file line numberDiff line numberDiff line change
@@ -364,33 +364,35 @@ class Meta:
364364

365365

366366
def test_deprecated_registerConnectionFieldFactory():
367-
registerConnectionFieldFactory(_TestSQLAlchemyConnectionField)
367+
with pytest.warns(DeprecationWarning):
368+
registerConnectionFieldFactory(_TestSQLAlchemyConnectionField)
368369

369-
class ReporterType(SQLAlchemyObjectType):
370-
class Meta:
371-
model = Reporter
372-
interfaces = (Node,)
370+
class ReporterType(SQLAlchemyObjectType):
371+
class Meta:
372+
model = Reporter
373+
interfaces = (Node,)
373374

374-
class ArticleType(SQLAlchemyObjectType):
375-
class Meta:
376-
model = Article
377-
interfaces = (Node,)
375+
class ArticleType(SQLAlchemyObjectType):
376+
class Meta:
377+
model = Article
378+
interfaces = (Node,)
378379

379-
assert isinstance(ReporterType._meta.fields['articles'].type(), _TestSQLAlchemyConnectionField)
380+
assert isinstance(ReporterType._meta.fields['articles'].type(), _TestSQLAlchemyConnectionField)
380381

381382

382383
def test_deprecated_unregisterConnectionFieldFactory():
383-
registerConnectionFieldFactory(_TestSQLAlchemyConnectionField)
384-
unregisterConnectionFieldFactory()
384+
with pytest.warns(DeprecationWarning):
385+
registerConnectionFieldFactory(_TestSQLAlchemyConnectionField)
386+
unregisterConnectionFieldFactory()
385387

386-
class ReporterType(SQLAlchemyObjectType):
387-
class Meta:
388-
model = Reporter
389-
interfaces = (Node,)
388+
class ReporterType(SQLAlchemyObjectType):
389+
class Meta:
390+
model = Reporter
391+
interfaces = (Node,)
390392

391-
class ArticleType(SQLAlchemyObjectType):
392-
class Meta:
393-
model = Article
394-
interfaces = (Node,)
393+
class ArticleType(SQLAlchemyObjectType):
394+
class Meta:
395+
model = Article
396+
interfaces = (Node,)
395397

396-
assert not isinstance(ReporterType._meta.fields['articles'].type(), _TestSQLAlchemyConnectionField)
398+
assert not isinstance(ReporterType._meta.fields['articles'].type(), _TestSQLAlchemyConnectionField)

0 commit comments

Comments
 (0)