Skip to content

Commit 08d518d

Browse files
author
Ryan P Kilby
committed
Deepcopy base filters for exclusion
1 parent 5ac705d commit 08d518d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

rest_framework_filters/filterset.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,13 @@ def expand_filters(self):
115115

116116
# include exclusion keys
117117
if exclude_name in self.data:
118-
f = copy.deepcopy(f)
119-
f.exclude = not f.exclude
120-
requested_filters[exclude_name] = f
118+
# deepcopy the *base* filter to prevent copying of model & parent
119+
f_copy = copy.deepcopy(self.base_filters[filter_name])
120+
f_copy.parent = f.parent
121+
f_copy.model = f.model
122+
f_copy.exclude = not f.exclude
123+
124+
requested_filters[exclude_name] = f_copy
121125

122126
# include filters from related subsets
123127
if isinstance(f, filters.RelatedFilter) and filter_name in related_data:

0 commit comments

Comments
 (0)