Skip to content

Commit

Permalink
LITE-20265 SelectFields can't be used in common filters
Browse files Browse the repository at this point in the history
  • Loading branch information
maxipavlovic committed Oct 8, 2021
1 parent fba7d06 commit 5686bec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion dj_rql/filter_cls.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
SUPPORTED_FIELD_TYPES,
SearchOperators,
)
from dj_rql.drf.fields import SelectField
from dj_rql.exceptions import RQLFilterLookupError, RQLFilterParsingError, RQLFilterValueError
from dj_rql.openapi import RQLFilterClassSpecification
from dj_rql.parser import RQLParser
Expand Down Expand Up @@ -266,9 +267,14 @@ def build_q_for_filter(self, data):
filter_lookup = self._get_filter_lookup(
filter_name, operator, str_value, available_lookups, null_values,
)
django_field = base_item.get('field')
if django_field and isinstance(django_field, SelectField):
raise RQLFilterLookupError(**self._get_error_details(
filter_name, filter_lookup, str_value,
))

django_lookup = self._get_django_lookup(filter_lookup, str_value, null_values)

django_field = base_item.get('field')
use_repr = base_item.get('use_repr', False)

typed_value = None
Expand Down
1 change: 1 addition & 0 deletions tests/test_filter_cls/test_fields_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ def test_datetime_field_fail(filter_name, bad_value):
@pytest.mark.parametrize('filter_name,value', [
('amazon_rating', '1.23'), ('page.number', '5'),
('int_choice_field_repr', 'I'), ('str_choice_field_repr', 'I'),
('select_author', 'value'),
])
def test_field_lookup_fail(filter_name, value, bad_operator):
assert_filter_field_lookup_error(filter_name, bad_operator, value)
Expand Down

0 comments on commit 5686bec

Please sign in to comment.