Skip to content

Fix method name collision #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
Unreleased:
-----------

v0.10.2:
--------

This is a maintenance release that fixes compatibility with django-filter.

* 189 Fix method name collision


v0.10.1:
--------

This is a maintenance release that fixes the following bugs:

* #172 Prevent deepcopying of filter's parent


v0.10.0:
--------

Expand Down
10 changes: 5 additions & 5 deletions rest_framework_filters/filterset.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,22 @@ def expand_filters(self):
return requested_filters

@classmethod
def get_filter_name(cls, param):
def get_param_filter_name(cls, param):
"""
Get the filter name for the request data parameter.

ex::

# regular attribute filters
name = FilterSet.get_filter_name('email')
name = FilterSet.get_param_filter_name('email')
assert name == 'email'

# exclusion filters
name = FilterSet.get_filter_name('email!')
name = FilterSet.get_param_filter_name('email!')
assert name == 'email'

# related filters
name = FilterSet.get_filter_name('author__email')
name = FilterSet.get_param_filter_name('author__email')
assert name == 'author'

"""
Expand Down Expand Up @@ -217,7 +217,7 @@ def get_subset(cls, params):
# param names that traverse relations are translated to just the local
# filter names. eg, `author__username` => `author`. Empty values are
# removed, as they indicate an unknown field eg, author__foobar__isnull
filter_names = [cls.get_filter_name(param) for param in params]
filter_names = [cls.get_param_filter_name(param) for param in params]
filter_names = [f for f in filter_names if f is not None]

# attempt to retrieve related filterset subset from the cache
Expand Down
32 changes: 16 additions & 16 deletions tests/test_filterset.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,32 +162,32 @@ class Meta:
self.assertIs(F.base_filters['id__in'], f)


class GetFilterNameTests(TestCase):
class GetParamFilterNameTests(TestCase):

def test_regular_filter(self):
name = UserFilter.get_filter_name('email')
name = UserFilter.get_param_filter_name('email')
self.assertEqual('email', name)

def test_exclusion_filter(self):
name = UserFilter.get_filter_name('email!')
name = UserFilter.get_param_filter_name('email!')
self.assertEqual('email', name)

def test_non_filter(self):
name = UserFilter.get_filter_name('foobar')
name = UserFilter.get_param_filter_name('foobar')
self.assertEqual(None, name)

def test_related_filter(self):
# 'exact' matches
name = NoteFilterWithRelated.get_filter_name('author')
name = NoteFilterWithRelated.get_param_filter_name('author')
self.assertEqual('author', name)

# related attribute filters
name = NoteFilterWithRelated.get_filter_name('author__email')
name = NoteFilterWithRelated.get_param_filter_name('author__email')
self.assertEqual('author', name)

# non-existent related filters should match, as it's the responsibility
# of the related filterset to handle non-existent filters
name = NoteFilterWithRelated.get_filter_name('author__foobar')
name = NoteFilterWithRelated.get_param_filter_name('author__foobar')
self.assertEqual('author', name)

def test_twice_removed_related_filter(self):
Expand All @@ -199,21 +199,21 @@ class Meta:
model = Post
fields = []

name = PostFilterWithDirectAuthor.get_filter_name('note__title')
name = PostFilterWithDirectAuthor.get_param_filter_name('note__title')
self.assertEqual('note', name)

# 'exact' matches, preference more specific filter name, as less specific
# filter may not have related access.
name = PostFilterWithDirectAuthor.get_filter_name('note__author')
name = PostFilterWithDirectAuthor.get_param_filter_name('note__author')
self.assertEqual('note__author', name)

# related attribute filters
name = PostFilterWithDirectAuthor.get_filter_name('note__author__email')
name = PostFilterWithDirectAuthor.get_param_filter_name('note__author__email')
self.assertEqual('note__author', name)

# non-existent related filters should match, as it's the responsibility
# of the related filterset to handle non-existent filters
name = PostFilterWithDirectAuthor.get_filter_name('note__author__foobar')
name = PostFilterWithDirectAuthor.get_param_filter_name('note__author__foobar')
self.assertEqual('note__author', name)

def test_name_hiding(self):
Expand All @@ -226,19 +226,19 @@ class Meta:
model = Post
fields = []

name = PostFilterNameHiding.get_filter_name('note__author')
name = PostFilterNameHiding.get_param_filter_name('note__author')
self.assertEqual('note__author', name)

name = PostFilterNameHiding.get_filter_name('note__title')
name = PostFilterNameHiding.get_param_filter_name('note__title')
self.assertEqual('note', name)

name = PostFilterNameHiding.get_filter_name('note')
name = PostFilterNameHiding.get_param_filter_name('note')
self.assertEqual('note', name)

name = PostFilterNameHiding.get_filter_name('note2')
name = PostFilterNameHiding.get_param_filter_name('note2')
self.assertEqual('note2', name)

name = PostFilterNameHiding.get_filter_name('note2__author')
name = PostFilterNameHiding.get_param_filter_name('note2__author')
self.assertEqual('note2', name)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_implicit_date_filters(self):
p = list(f.qs)[0]
self.assertEqual(p.name, "John")

@override_settings(USE_TZ=True)
@override_settings(USE_TZ=True, TIME_ZONE='UTC')
def test_datetime_timezone_awareness(self):
# Addresses issue #24 - ensure that datetime strings terminating
# in 'Z' are correctly handled.
Expand Down