diff --git a/src/marshmallow/schema.py b/src/marshmallow/schema.py index cde8c080f..4e7fd828f 100644 --- a/src/marshmallow/schema.py +++ b/src/marshmallow/schema.py @@ -374,7 +374,7 @@ def __init__( context: dict | None = None, load_only: types.StrSequenceOrSet = (), dump_only: types.StrSequenceOrSet = (), - partial: bool | types.StrSequenceOrSet = False, + partial: bool | types.StrSequenceOrSet | None = None, unknown: str | None = None, ): # Raise error if only or exclude is passed as string, not list of strings @@ -590,7 +590,7 @@ def _deserialize( *, error_store: ErrorStore, many: bool = False, - partial=False, + partial=None, unknown=RAISE, index=None, ) -> _T | list[_T]: @@ -657,7 +657,7 @@ def _deserialize( f[len_prefix:] for f in partial if f.startswith(prefix) ] d_kwargs["partial"] = sub_partial - else: + elif partial is not None: d_kwargs["partial"] = partial def getter( @@ -1089,7 +1089,7 @@ def _invoke_load_processors( *, many: bool, original_data, - partial: bool | types.StrSequenceOrSet, + partial: bool | types.StrSequenceOrSet | None, ): # This has to invert the order of the dump processors, so run the pass_many # processors first. @@ -1166,7 +1166,7 @@ def _invoke_schema_validators( data, original_data, many: bool, - partial: bool | types.StrSequenceOrSet, + partial: bool | types.StrSequenceOrSet | None, field_errors: bool = False, ): for attr_name in self._hooks[(VALIDATES_SCHEMA, pass_many)]: diff --git a/tests/test_deserialization.py b/tests/test_deserialization.py index 6a2c7a87b..29cab67b7 100644 --- a/tests/test_deserialization.py +++ b/tests/test_deserialization.py @@ -2236,6 +2236,21 @@ class SchemaB(Schema): with pytest.raises(ValidationError): SchemaB().load(b_dict, partial=("z.y",)) + def test_nested_partial_default(self): + class SchemaA(Schema): + x = fields.Integer(required=True) + y = fields.Integer(required=True) + + class SchemaB(Schema): + z = fields.Nested(SchemaA(partial=("x",))) + + b_dict = {"z": {"y": 42}} + # Nested partial args should be respected. + result = SchemaB().load(b_dict) + assert result["z"]["y"] == 42 + with pytest.raises(ValidationError): + SchemaB().load({"z": {"x": 0}}) + @pytest.mark.parametrize("FieldClass", ALL_FIELDS) def test_required_field_failure(FieldClass): # noqa