Skip to content

Commit 515060b

Browse files
committed
Ensure that UnsortedSQLAlchemyConnectionField skips sort argument if it gets passed.
1 parent b91fede commit 515060b

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

graphene_sqlalchemy/batching.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ async def batch_load_fn(self, parents):
9595

9696

9797
def get_batch_resolver(relationship_prop):
98-
"""get the resolve function for the given relationship."""
98+
"""Get the resolve function for the given relationship."""
9999

100100
def _get_loader(relationship_prop):
101101
"""Retrieve the cached loader of the given relationship."""

graphene_sqlalchemy/fields.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,19 @@ def wrap_resolve(self, parent_resolver):
125125
# TODO Remove in next major version
126126
class UnsortedSQLAlchemyConnectionField(SQLAlchemyConnectionField):
127127
def __init__(self, type_, *args, **kwargs):
128-
super(UnsortedSQLAlchemyConnectionField, self).__init__(type_, *args, **kwargs)
128+
if "sort" in kwargs and kwargs["sort"] is not None:
129+
warnings.warn(
130+
"UnsortedSQLAlchemyConnectionField does not support sorting. "
131+
"All sorting arguments will be ignored."
132+
)
133+
kwargs["sort"] = None
129134
warnings.warn(
130135
"UnsortedSQLAlchemyConnectionField is deprecated and will be removed in the next "
131-
"major version. Use SQLAlchemyConnectionField instead and set `sort = None` "
132-
"if you want to disable sorting.",
136+
"major version. Use SQLAlchemyConnectionField instead and either don't "
137+
"provide the `sort` argument or set it to None if you do not want sorting.",
133138
DeprecationWarning,
134139
)
140+
super(UnsortedSQLAlchemyConnectionField, self).__init__(type_, *args, **kwargs)
135141

136142

137143
class BatchSQLAlchemyConnectionField(SQLAlchemyConnectionField):

graphene_sqlalchemy/tests/test_fields.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ def test_type_assert_object_has_connection():
6464
##
6565

6666

67+
def test_unsorted_connection_field_removes_sort_arg_if_passed():
68+
editor = UnsortedSQLAlchemyConnectionField(
69+
Editor.connection,
70+
sort=Editor.sort_argument(has_default=True)
71+
)
72+
assert "sort" not in editor.args
73+
74+
6775
def test_sort_added_by_default():
6876
field = SQLAlchemyConnectionField(Pet.connection)
6977
assert "sort" in field.args

0 commit comments

Comments
 (0)