Skip to content

Commit f3e092c

Browse files
bewingrpkilby
authored andcommitted
Test filter param name existence (#281)
1 parent e14c66b commit f3e092c

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

rest_framework_filters/filterset.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ def get_param_filter_name(cls, param, rel=None):
172172
'email'
173173
174174
"""
175+
# check for empty param
176+
if not param:
177+
return param
178+
175179
# strip the rel prefix from the param name.
176180
prefix = '%s%s' % (rel or '', LOOKUP_SEP)
177181
if rel and param.startswith(prefix):

tests/test_filtering.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,11 @@ class PostFilter(FilterSet):
385385
self.assertEqual(f.__module__, 'tests.test_filtering')
386386
self.assertEqual(f.__name__, 'LocalTagFilter')
387387

388+
def test_empty_param_name(self):
389+
GET = {'': 'foo', 'author': User.objects.get(username='user2').pk}
390+
f = NoteFilter(GET, queryset=Note.objects.all())
391+
self.assertEqual(len(list(f.qs)), 1)
392+
388393

389394
class AnnotationTests(TestCase):
390395
# TODO: these tests should somehow assert that the annotation method is

0 commit comments

Comments
 (0)