Skip to content

Commit 50d4a89

Browse files
authored
Merge pull request #13 from maxipavlovic/bugfix/LITE-13440
LITE-13440 Fixed wrong `path` in OptimizationArgs for logical namespaces
2 parents af65743 + 930a5b4 commit 50d4a89

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

dj_rql/filter_cls.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,15 +595,19 @@ def _fill_select_tree(self, f_name, full_f_name, select_tree,
595595
elif parent_qs and (not isinstance(parent_qs, Annotation)):
596596
changed_qs = qs.rebuild(parent_qs)
597597

598+
is_logical_namespace = len(filter_name_parts) > 1
599+
path = ''
598600
for index, filter_name_part in enumerate(filter_name_parts):
601+
path += filter_name_part
599602
current_select_tree.setdefault(filter_name_part, {
600603
'hidden': hidden,
601604
'fields': {},
602605
'namespace': namespace or (index != last_filter_name_part_index),
603606
'qs': changed_qs,
604-
'path': full_f_name,
607+
'path': path if is_logical_namespace else full_f_name,
605608
})
606609
current_select_tree = current_select_tree[filter_name_part]['fields']
610+
path += '.'
607611

608612
return current_select_tree, parent_qs if not qs else changed_qs
609613

tests/test_filter_cls/test_select.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from django.core.exceptions import FieldError
77
from django.db.models import CharField, IntegerField, Value
88

9+
from dj_rql.drf.fields import SelectField
910
from dj_rql.exceptions import RQLFilterParsingError
1011
from dj_rql.filter_cls import RQLFilterClass
1112
from dj_rql.qs import AN, CH, PR, NPR, NSR, SR
@@ -793,3 +794,27 @@ class AnnotationCls(RQLFilterClass):
793794

794795
with pytest.raises(FieldError):
795796
AnnotationCls(book_qs).apply_filters('ft=2')
797+
798+
799+
def test_deselect_namespace():
800+
class Cls(SelectFilterCls):
801+
FILTERS = (
802+
{
803+
'filter': 'ns.author',
804+
'dynamic': True,
805+
'qs': NSR('author'),
806+
'field': SelectField(),
807+
},
808+
{
809+
'namespace': 'ns2',
810+
'source': 'author',
811+
'qs': AN(ns=Value('abc', CharField(max_length=128))),
812+
'filters': ('id',),
813+
},
814+
)
815+
816+
_, qs = Cls(book_qs).apply_filters('')
817+
assert qs.query.select_related == {'author': {}}
818+
819+
_, qs = Cls(book_qs).apply_filters('select(-ns,-ns2)')
820+
assert not qs.query.select_related

0 commit comments

Comments
 (0)