marshmallow
marshmallow copied to clipboard
Are nested options applied correctly?
Experimenting with only, I noticed it is possible to assign an invalid value to a Field's only attribute.
Looking at the code in the __apply_nested_option method of the schema.Schema class, there is no validation done when propagating the only value to a field.
from marshmallow import fields, Schema
class S(Schema):
f = fields.Str()
S(only=['f.a.b'])
<S(many=False)> # actual output.
ValueError: Option: 'only' with value: 'a.b' is not valid for Field: 'f'. # expected output.
All comments are welcome.
I wouldn't say it is a bug, but we already try to validate inputs to catch typos and we could add a check for this as well.
Contribution welcome if someone is willing to investigate.