Skip to content

Commit 36dd430

Browse files
author
Ryan P Kilby
committed
Deprecate 'in' lookup filters & fields
1 parent 074aaef commit 36dd430

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

rest_framework_filters/fields.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
2+
import warnings
13
from django import forms
4+
25
from django_filters.widgets import BooleanWidget
36

47

@@ -7,6 +10,14 @@ class BooleanField(forms.BooleanField):
710

811

912
class ArrayDecimalField(forms.DecimalField):
13+
def __init__(self, *args, **kwargs):
14+
super(ArrayDecimalField, self).__init__(*args, **kwargs)
15+
warnings.warn(
16+
'ArrayDecimalField is deprecated and no longer necessary. See: '
17+
'https://github.com/philipn/django-rest-framework-filters/issues/62',
18+
DeprecationWarning, stacklevel=3
19+
)
20+
1021
def clean(self, value):
1122
if value is None:
1223
return None
@@ -18,6 +29,14 @@ def clean(self, value):
1829

1930

2031
class ArrayCharField(forms.CharField):
32+
def __init__(self, *args, **kwargs):
33+
super(ArrayCharField, self).__init__(*args, **kwargs)
34+
warnings.warn(
35+
'ArrayCharField is deprecated and no longer necessary. See: '
36+
'https://github.com/philipn/django-rest-framework-filters/issues/62',
37+
DeprecationWarning, stacklevel=3
38+
)
39+
2140
def clean(self, value):
2241
if value is None:
2342
return None

rest_framework_filters/filters.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import absolute_import
22
from __future__ import unicode_literals
33

4+
import warnings
45
from django.utils import six
56

67
from django_filters.filters import *
@@ -60,10 +61,26 @@ class BooleanFilter(BooleanFilter):
6061
class InSetNumberFilter(Filter):
6162
field_class = fields.ArrayDecimalField
6263

64+
def __init__(self, *args, **kwargs):
65+
super(InSetNumberFilter, self).__init__(*args, **kwargs)
66+
warnings.warn(
67+
'InSetNumberFilter is deprecated and no longer necessary. See: '
68+
'https://github.com/philipn/django-rest-framework-filters/issues/62',
69+
DeprecationWarning, stacklevel=2
70+
)
71+
6372

6473
class InSetCharFilter(Filter):
6574
field_class = fields.ArrayCharField
6675

76+
def __init__(self, *args, **kwargs):
77+
super(InSetCharFilter, self).__init__(*args, **kwargs)
78+
warnings.warn(
79+
'InSetCharFilter is deprecated and no longer necessary. See: '
80+
'https://github.com/philipn/django-rest-framework-filters/issues/62',
81+
DeprecationWarning, stacklevel=2
82+
)
83+
6784

6885
class MethodFilter(Filter):
6986
"""

tests/test_deprecations.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,38 @@ class Meta:
9999
fields = ['last_login']
100100

101101
self.assertEqual(len(w), 0)
102+
103+
104+
class InLookupDeprecationTests(TestCase):
105+
106+
def test_char_filter_deprecations(self):
107+
with warnings.catch_warnings(record=True) as w:
108+
warnings.simplefilter("always")
109+
110+
class F(FilterSet):
111+
username__in = filters.InSetCharFilter(name='username', lookup_expr='in')
112+
113+
class Meta:
114+
model = User
115+
116+
self.assertEqual(len(w), 1)
117+
118+
# Generate another warning for field
119+
F({'username__in': 'a'}).qs
120+
self.assertEqual(len(w), 2)
121+
122+
def test_number_filter_deprecations(self):
123+
with warnings.catch_warnings(record=True) as w:
124+
warnings.simplefilter("always")
125+
126+
class F(FilterSet):
127+
id__in = filters.InSetNumberFilter(name='id', lookup_expr='in')
128+
129+
class Meta:
130+
model = User
131+
132+
self.assertEqual(len(w), 1)
133+
134+
# Generate another warning for field
135+
F({'id__in': '1'}).qs
136+
self.assertEqual(len(w), 2)

0 commit comments

Comments
 (0)