Skip to content

Commit 70707d8

Browse files
committed
fix: do not add filters to non list fields
Thanks to @g-as for reporting this regression from the last release.
1 parent 4454e73 commit 70707d8

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

strawberry_django/filters.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ def arguments(self) -> List[StrawberryArgument]:
188188
and self.origin._type_definition.name == "Query"
189189
):
190190
arguments.append(argument("pk", strawberry.ID, is_optional=False))
191+
elif self.django_model and not self.is_list:
192+
# Do not add filters to non list fields
193+
pass
191194
elif filters and filters is not UNSET:
192195
arguments.append(argument("filters", filters))
193196
return super().arguments + arguments

tests/filters/test_filters.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,11 @@ def test_enum(query, fruits):
252252

253253
@pytest.mark.django_db(transaction=True)
254254
def test_pk_inserted_for_root_field_only():
255-
@strawberry_django.type(models.Group)
255+
@strawberry_django.filters.filter(models.Group)
256+
class GroupFilter:
257+
name: str
258+
259+
@strawberry_django.type(models.Group, filters=GroupFilter)
256260
class GroupType(models.Group):
257261
name: strawberry.auto
258262

0 commit comments

Comments
 (0)