Skip to content

Commit

Permalink
Fix the default inheritance of nested partial schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
deckar01 committed Jul 18, 2023
1 parent 1b2ab4f commit 10afde1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/marshmallow/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 15 additions & 0 deletions tests/test_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 10afde1

Please sign in to comment.