mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-22 01:27:01 +03:00
fix: declaration of required variable in filters v3 (#1137)
* fix: declaration of required variable * Add unit test * Fix formating Co-authored-by: Thomas Leonard <thomas@loftorbital.com>
This commit is contained in:
parent
ea593b673f
commit
6046a710c8
|
@ -16,7 +16,7 @@ pytestmark = []
|
|||
|
||||
if DJANGO_FILTER_INSTALLED:
|
||||
import django_filters
|
||||
from django_filters import FilterSet, NumberFilter
|
||||
from django_filters import FilterSet, NumberFilter, OrderingFilter
|
||||
|
||||
from graphene_django.filter import (
|
||||
GlobalIDFilter,
|
||||
|
@ -1275,3 +1275,22 @@ def test_filter_string_contains():
|
|||
assert result.data == {
|
||||
"people": {"edges": [{"node": {"name": "Joe"}}, {"node": {"name": "Bob"}},]}
|
||||
}
|
||||
|
||||
|
||||
def test_only_custom_filters():
|
||||
class ReporterFilter(FilterSet):
|
||||
class Meta:
|
||||
model = Reporter
|
||||
fields = []
|
||||
|
||||
some_filter = OrderingFilter(fields=("name",))
|
||||
|
||||
class ReporterFilterNode(DjangoObjectType):
|
||||
class Meta:
|
||||
model = Reporter
|
||||
interfaces = (Node,)
|
||||
fields = "__all__"
|
||||
filterset_class = ReporterFilter
|
||||
|
||||
field = DjangoFilterConnectionField(ReporterFilterNode)
|
||||
assert_arguments(field, "some_filter")
|
||||
|
|
|
@ -37,6 +37,7 @@ def get_filtering_args_from_filterset(filterset_class, type):
|
|||
registry = type._meta.registry
|
||||
for name, filter_field in filterset_class.base_filters.items():
|
||||
filter_type = filter_field.lookup_expr
|
||||
required = filter_field.extra.get("required", False)
|
||||
field_type = None
|
||||
form_field = None
|
||||
|
||||
|
@ -47,8 +48,6 @@ def get_filtering_args_from_filterset(filterset_class, type):
|
|||
or isinstance(filter_field, ArrayFilter)
|
||||
):
|
||||
# Get the filter field for filters that are no explicitly declared.
|
||||
|
||||
required = filter_field.extra.get("required", False)
|
||||
if filter_type == "isnull":
|
||||
field = graphene.Boolean(required=required)
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue
Block a user