@@ -482,6 +482,9 @@ class ParentSchema(Schema):
482482 :param only: A list or tuple of fields to marshal. If `None`, all fields are marshalled.
483483 This parameter takes precedence over ``exclude``.
484484 :param many: Whether the field is a collection of objects.
485+ If `None` (default), and nested `Schema` instance is provided, ``many`` is not overridden.
486+ If `None` (default), and `Schema` subclass is provided, schema instance sets ``many`` as False.
487+ If `True | False` nested `[nested_field].schema.many` is overridden.
485488 :param unknown: Whether to exclude, include, or raise an error for unknown
486489 fields in the data. Use `EXCLUDE`, `INCLUDE` or `RAISE`.
487490 :param kwargs: The same keyword arguments that :class:`Field` receives.
@@ -502,7 +505,7 @@ def __init__(
502505 * ,
503506 only : types .StrSequenceOrSet | None = None ,
504507 exclude : types .StrSequenceOrSet = (),
505- many : bool = False ,
508+ many : bool | None = None ,
506509 unknown : types .UnknownOption | None = None ,
507510 ** kwargs : Unpack [_BaseFieldKwargs ],
508511 ):
@@ -537,7 +540,7 @@ def schema(self) -> Schema:
537540
538541 if isinstance (nested , Schema ):
539542 self ._schema = copy .copy (nested )
540- # Respect only and exclude passed from parent and re-initialize fields
543+ # Respect only and exclude and many passed from parent and re-initialize fields
541544 set_class = typing .cast ("type[set]" , self ._schema .set_class )
542545 if self .only is not None :
543546 if self ._schema .only is not None :
@@ -548,6 +551,8 @@ def schema(self) -> Schema:
548551 if self .exclude :
549552 original = self ._schema .exclude
550553 self ._schema .exclude = set_class (self .exclude ) | set_class (original )
554+ if self .many is not None :
555+ self ._schema .many = self .many
551556 self ._schema ._init_fields ()
552557 else :
553558 if isinstance (nested , type ) and issubclass (nested , Schema ):
@@ -560,7 +565,7 @@ def schema(self) -> Schema:
560565 else :
561566 schema_class = class_registry .get_class (nested , all = False ) # type: ignore[unreachable]
562567 self ._schema = schema_class (
563- many = self .many ,
568+ many = bool ( self .many ) ,
564569 only = self .only ,
565570 exclude = self .exclude ,
566571 load_only = self ._nested_normalized_option ("load_only" ),
0 commit comments