Validate filter params #1719
-
ProblemIf I define a class PersonFilter(FilterSet):
class Meta:
model = Person
fields = [
'name',
'height',
] And I then call the endpoint with a misspelled filter param... requests.get(url, params={'nome': 'Susan'}) Then I feel like the endpoint should raise an error. Instead, it merely ignores this filter param and returns all SolutionsI had thought the unknown_field_behavior option would fix this, but apparently it already defaults to |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Hi @isaac-blanc. So first you have to decide if the FilterSet parameters are both required and the only allowable ones in the query string. If you also want to allow (e.g.) pagination, then you can't just insist that the keys in However, given all that, you can check The DRF backend does this when filtering if you set the django-filter/django_filters/rest_framework/backends.py Lines 70 to 71 in 635343e If you're dealing with the FilterSet directly in your view, then you'd do similar there. |
Beta Was this translation helpful? Give feedback.
Just got back to this. Have extended
FilterSet
as shown below. As far as I can tell, it works great. Would be grateful if you could cast an eye over it, although of course no worries if you haven't got the time. Thanks for your help!