ensure popped values are persisted

This commit is contained in:
Matthias Mair 2025-10-13 22:21:09 +02:00
parent 81f26c7073
commit 994259a71d
No known key found for this signature in database
GPG Key ID: A593429DDA23B66A
1 changed files with 4 additions and 2 deletions

View File

@ -53,7 +53,6 @@ class OptFilter:
class PathScopedMixin(serializers.Serializer):
"""Mixin to disable a serializer field based on kwargs passed to the view."""
no_filter = False
_was_filtered = False
def __init__(self, *args, **kwargs):
@ -77,10 +76,13 @@ class PathScopedMixin(serializers.Serializer):
}
# Remove filter args from kwargs to avoid issues with super().__init__
poped_kwargs = {} # store popped kwargs as a arg might be reused for multiple fields
tgs_vals = {}
for k, v in self.filter_targets.items():
pop_ref = v['name'] or k
val = kwargs.pop(pop_ref, None)
val = kwargs.pop(pop_ref, poped_kwargs.get(pop_ref))
if val:
poped_kwargs[pop_ref] = val
tgs_vals[k] = str2bool(val) if isinstance(val, str) else val
self.filter_target_values = tgs_vals