Skip to content

Commit b47da8b

Browse files
authored
Merge pull request #8 from cloudblue/opt/LITE-27331
LITE-27331 Exact (non-regexp) match is used for string filters
2 parents 440e555 + 8491b91 commit b47da8b

File tree

3 files changed

+66
-44
lines changed

3 files changed

+66
-44
lines changed

dj_mongoengine_rql/filter_cls.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright © 2022 Ingram Micro. All rights reserved.
2+
# Copyright © 2023 Ingram Micro. All rights reserved.
33
#
44

55
from dj_rql.constants import DjangoLookups
@@ -40,8 +40,9 @@ def _get_decimal_field_precision(cls, field):
4040
return field.precision
4141

4242
def _build_django_q(self, filter_item, django_lookup, filter_lookup, typed_value):
43-
if django_lookup == DjangoLookups.NULL:
44-
q = self.Q_CLS(**{filter_item['orm_route']: None})
43+
if django_lookup in (DjangoLookups.EXACT, DjangoLookups.NULL):
44+
v = typed_value if django_lookup == DjangoLookups.EXACT else None
45+
q = self.Q_CLS(**{filter_item['orm_route']: v})
4546
return ~q if filter_lookup == FilterLookups.NE else q
4647

4748
if filter_lookup != FilterLookups.NE:

poetry.lock

Lines changed: 41 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/test_filter_cls.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#
2-
# Copyright © 2022 CloudBlue LLC. All rights reserved.
2+
# Copyright © 2023 Ingram Micro. All rights reserved.
33
#
44

5+
from typing import Pattern
6+
57
from py_rql.constants import FilterLookups
68

79
from dj_mongoengine_rql.filter_cls import MongoengineRQLFilterClass
@@ -61,6 +63,24 @@ def test_not():
6163
assert qs.query.q == {'$nor': [{'other_int_f': 120}], 'other_int_f': 1}
6264

6365

66+
def test_eq_str():
67+
_, qs = DocFilterClass(Doc.objects).apply_filters('str_f=x')
68+
69+
assert qs.query.q == {'str_f': 'x'}
70+
71+
72+
def test_like_str():
73+
_, qs = DocFilterClass(Doc.objects).apply_filters('like(str_f,*x*s*)')
74+
75+
assert isinstance(qs.query.q['str_f'], Pattern)
76+
77+
78+
def test_ne_str():
79+
_, qs = DocFilterClass(Doc.objects).apply_filters('str_f=ne=x')
80+
81+
assert qs.query.q == {'$nor': [{'str_f': 'x'}]}
82+
83+
6484
def test_null():
6585
_, qs = DocFilterClass(Doc.objects).apply_filters('flt=null()')
6686

0 commit comments

Comments
 (0)