Skip to content

Commit

Permalink
only and exclude nested props fix
Browse files Browse the repository at this point in the history
  • Loading branch information
regiscamimura committed Aug 2, 2023
1 parent df7b8fa commit 26bc460
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions worf/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ class Serializer(marshmallow.Schema):
}

def __init__(self, only=(), *args, **kwargs):
self.raw_only = only
self.raw_exclude = kwargs.get("exclude", None)
super().__init__(only=only or None, *args, **kwargs)

def __call__(self, **kwargs):
only = self.only
only = self.raw_only
if self.only and kwargs.get("only"):
invalid_fields = set(kwargs.get("only")) - self.only
if invalid_fields:
Expand All @@ -111,7 +113,7 @@ def __call__(self, **kwargs):
return self.__class__(
context=kwargs.get("context", self.context),
dump_only=kwargs.get("dump_only", self.dump_only),
exclude=set(self.exclude or []) | set(kwargs.get("exclude") or []),
exclude=set(self.raw_exclude or []) | set(kwargs.get("exclude") or []),
load_only=kwargs.get("load_only", self.load_only),
many=kwargs.get("many", self.many),
only=only,
Expand Down

0 comments on commit 26bc460

Please sign in to comment.