Skip to content

Commit

Permalink
fix: do not add filters to non list fields
Browse files Browse the repository at this point in the history
Thanks to @g-as for reporting this regression from the last release.
  • Loading branch information
bellini666 committed Apr 3, 2023
1 parent 4454e73 commit 70707d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions strawberry_django/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ def arguments(self) -> List[StrawberryArgument]:
and self.origin._type_definition.name == "Query"
):
arguments.append(argument("pk", strawberry.ID, is_optional=False))
elif self.django_model and not self.is_list:
# Do not add filters to non list fields
pass
elif filters and filters is not UNSET:
arguments.append(argument("filters", filters))
return super().arguments + arguments
Expand Down
6 changes: 5 additions & 1 deletion tests/filters/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,11 @@ def test_enum(query, fruits):

@pytest.mark.django_db(transaction=True)
def test_pk_inserted_for_root_field_only():
@strawberry_django.type(models.Group)
@strawberry_django.filters.filter(models.Group)
class GroupFilter:
name: str

@strawberry_django.type(models.Group, filters=GroupFilter)
class GroupType(models.Group):
name: strawberry.auto

Expand Down

0 comments on commit 70707d8

Please sign in to comment.