Fix load parameter *unknow* propagation
When deserializing a data structure with the load method, the unknown was not propagated to the loading of nested data structures. As result, if a unknown field was present into a nested data structure a ValidationError was raised even if the load methd was called with unknown=EXCLUDE. This commit ensures that this parameter is now propagated also to the loading of nested data structures. fixes #1428
@lafrech @sloria What do you thing about this proposed fix? I tried to provide the required documentation to make this behavior explicit.
Nested.load() calls Schema.load() internally, so when an unknown argument is supplied to the Nested constructor, this PR causes all of the nested unknown options to be recursively overridden.
from marshmallow import fields, Schema, RAISE, INCLUDE, EXCLUDE
class C(Schema):
foo = fields.Str()
class Meta:
unknown = EXCLUDE
class B(Schema):
c = fields.Nested(C)
class A(Schema):
b = fields.Nested(B, unknown=INCLUDE)
class Meta:
unknown = RAISE
schema = A()
print(schema.load({
'b': {
'extra': 'good',
'c': {
'foo': 'bar',
'unexpected': 'bad'
}
}
}))
Current behavior (3.2.2):
{'b': {'c': {'foo': 'bar'}, 'extra': 'good'}}
Proposed behavior:
{'b': {'c': {'foo': 'bar', 'unexpected': 'bad'}, 'extra': 'good'}}
Any chance of this merging?