File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,9 @@ def get_filters(self):
122122 filterset_class = related_filter .filterset
123123 filter_names = [filterset_class .get_filter_name (param ) for param in rel_data .keys ()]
124124
125+ # filter out empty values - indicates an unknown field (author__foobar__isnull)
126+ filter_names = [f for f in filter_names if f is not None ]
127+
125128 # attempt to retrieve related filterset subset from the cache
126129 key = self .cache_key (filterset_class , filter_names )
127130 subset_class = self .cache_get (key )
Original file line number Diff line number Diff line change @@ -315,6 +315,25 @@ def test_get_filterset_subset(self):
315315 self .assertIn ('email' , filterset_class .base_filters )
316316 self .assertEqual (len (filterset_class .base_filters ), 1 )
317317
318+ def test_nonexistent_related_field (self ):
319+ """
320+ Invalid filter keys (including those on related filters) are invalid
321+ and should be ignored.
322+
323+ Related: https://github.com/philipn/django-rest-framework-filters/issues/58
324+ """
325+ GET = {
326+ 'author__nonexistent' : 'foobar' ,
327+ }
328+ f = NoteFilterWithRelated (GET , queryset = Note .objects .all ())
329+ self .assertEqual (len (list (f )), 4 )
330+
331+ GET = {
332+ 'author__nonexistent__isnull' : 'foobar' ,
333+ }
334+ f = NoteFilterWithRelated (GET , queryset = Note .objects .all ())
335+ self .assertEqual (len (list (f )), 4 )
336+
318337
319338class MethodFilterTests (TestCase ):
320339
You can’t perform that action at this time.
0 commit comments