18
18
missing as missing_ ,
19
19
resolve_field_instance ,
20
20
is_aware ,
21
+ UnknownParam ,
21
22
)
22
23
from marshmallow .exceptions import (
23
24
ValidationError ,
@@ -459,10 +460,6 @@ class ParentSchema(Schema):
459
460
:param many: Whether the field is a collection of objects.
460
461
:param unknown: Whether to exclude, include, or raise an error for unknown
461
462
fields in the data. Use `EXCLUDE`, `INCLUDE` or `RAISE`.
462
- :param propagate_unknown: If ``True``, the value for ``unknown`` will be
463
- applied to any ``Nested`` fields within the nested schema. Propagates down and allows
464
- ``Nested`` fields to apply their own ``unknown`` value. Note that this
465
- only has an effect when there are multiple layers of nesting
466
463
:param kwargs: The same keyword arguments that :class:`Field` receives.
467
464
"""
468
465
@@ -477,8 +474,7 @@ def __init__(
477
474
only : types .StrSequenceOrSet = None ,
478
475
exclude : types .StrSequenceOrSet = (),
479
476
many : bool = False ,
480
- unknown : str = None ,
481
- propagate_unknown : bool = None ,
477
+ unknown : typing .Union [str , UnknownParam ] = None ,
482
478
** kwargs
483
479
):
484
480
# Raise error if only or exclude is passed as string, not list of strings
@@ -498,8 +494,7 @@ def __init__(
498
494
self .only = only
499
495
self .exclude = exclude
500
496
self .many = many
501
- self .unknown = unknown
502
- self .propagate_unknown = propagate_unknown
497
+ self .unknown = UnknownParam .parse_if_str (unknown ) if unknown else None
503
498
self ._schema = None # Cached Schema instance
504
499
super ().__init__ (default = default , ** kwargs )
505
500
@@ -577,32 +572,18 @@ def _test_collection(self, value):
577
572
if many and not utils .is_collection (value ):
578
573
raise self .make_error ("type" , input = value , type = value .__class__ .__name__ )
579
574
580
- def _load (self , value , data , partial = None , unknown = None , propagate_unknown = None ):
575
+ def _load (self , value , data , partial = None , unknown = None ):
581
576
try :
582
577
valid_data = self .schema .load (
583
- value ,
584
- unknown = unknown or self .unknown ,
585
- propagate_unknown = propagate_unknown
586
- if propagate_unknown is not None
587
- else self .propagate_unknown ,
588
- partial = partial ,
578
+ value , unknown = unknown if unknown else self .unknown , partial = partial ,
589
579
)
590
580
except ValidationError as error :
591
581
raise ValidationError (
592
582
error .messages , valid_data = error .valid_data
593
583
) from error
594
584
return valid_data
595
585
596
- def _deserialize (
597
- self ,
598
- value ,
599
- attr ,
600
- data ,
601
- partial = None ,
602
- unknown = None ,
603
- propagate_unknown = None ,
604
- ** kwargs
605
- ):
586
+ def _deserialize (self , value , attr , data , partial = None , unknown = None , ** kwargs ):
606
587
"""Same as :meth:`Field._deserialize` with additional ``partial`` argument.
607
588
608
589
:param bool|tuple partial: For nested schemas, the ``partial``
@@ -616,18 +597,14 @@ def _deserialize(
616
597
# however, we should only respect `self.schema.unknown` if
617
598
# `auto_unknown` is False, meaning that it was set explicitly on the
618
599
# schema class or instance
619
- explicit_unknown = self .unknown or (
620
- self .schema .unknown if not self .schema .auto_unknown else None
600
+ explicit_unknown = (
601
+ self .unknown
602
+ if self .unknown
603
+ else (self .schema .unknown if not self .schema .auto_unknown else None )
621
604
)
622
605
if explicit_unknown :
623
606
unknown = explicit_unknown
624
- return self ._load (
625
- value ,
626
- data ,
627
- partial = partial ,
628
- unknown = unknown ,
629
- propagate_unknown = propagate_unknown ,
630
- )
607
+ return self ._load (value , data , partial = partial , unknown = unknown ,)
631
608
632
609
633
610
class Pluck (Nested ):
0 commit comments