marshmallow icon indicating copy to clipboard operation
marshmallow copied to clipboard

Are nested options applied correctly?

Open matuqam opened this issue 2 years ago • 1 comments

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.

matuqam avatar Sep 01 '23 23:09 matuqam

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.

lafrech avatar Sep 10 '23 19:09 lafrech