Can't use GlobalIDFilter as FilterSet field
See original GitHub issueI noticed that when I was trying to use a GlobalIDFilter
as a FilterSet field, it doesn’t call the filter method (both my custom method filter_table_id
and GlobalIDFilter.filter
is not called) and returns all of the records in the table. If I use a CharFilter instead of a GlobalIDFilter, it works and filters as expected.
This works. But type is String
in queries.
class ModelFilter(FilterSet):
def filter_table_id(self, queryset, name, value):
_, _id = from_global_id(value)
return queryset.filter(table1__table2__table3__id=_id)
table_id = CharFilter(method='filter_table_id')
class Meta:
model = DBModel
fields = {
'name': ['exact', 'icontains'],
'table_id': ['exact'],
}
But if I replace the CharFilter
with GlobalIDFilter
, the type is ID
in the query, but all the records are returned, none are filtered out.
class ModelFilter(FilterSet):
def filter_table_id(self, queryset, name, value):
_, _id = from_global_id(value)
return queryset.filter(table1__table2__table3__id=_id)
table_id = GlobalIDFilter(method='filter_table_id')
class Meta:
model = DBModel
fields = {
'name': ['exact', 'icontains'],
'table_id': ['exact'],
}
I tried to see why it was not working, but I could not find out why the filter function nor my filter_table_id
was being called.
Am I using the wrong thing for filtering?
Is there a better way to do what I want?
I am using venv with:
- Python 3.7.0 (default, Sep 12 2018, 18:30:08), the default Python3.7 Ubuntu 18.04 package.
- graphene-django==2.2.0
- django-filter==2.0.0
- graphene==2.1.3
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
How to filter a query by a list of ids in GraphQL using ...
GlobalIDMultipleChoiceFilter from django-graphene kinda solves this issue, if you put "in" in the field name. You can create filters like
Read more >django-filter - Graphene-Python
The filter_fields parameter is used to specify the fields which can be filtered upon. The value specified here is passed directly to django-filter...
Read more >How to use the graphene-django.graphene_django.filter ...
To help you get started, we've selected a few graphene-django examples, based on popular ways it is used in public projects. Secure your...
Read more >Passing Parameter from Field Maps to Survey123 INBOX Edit
I am trying to pass an attribute from Field Maps to Survey123, ... the globalId parameter as well (globalId=, filter only filters the...
Read more >Tips and Solutions — django-filter 22.1 documentation
You should use filters that match the data type of the lookup expression instead of the data type underlying the model field. The...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m not that familiar with graphene-django, but the below is where the filterset is created and called: https://github.com/graphql-python/graphene-django/blob/dc561c68c49d1a91637503f765857d819c36769a/graphene_django/filter/fields.py#L92-L96
Does it make sense for
DjangoFilterConnectionField.connection_resolver
to raise validation errors? If so, then the code should look like:I believe this is an issue with django-filter and not graphene-django. Can we close this?