You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I discovered the hard way that fields.Nested silently ignores the many parameter when it's passed an instance. It's my fault, I can see in the docstring that this behaviour is described, but that didn't stop me wasting a load of time debugging the error. I see that using many=True is no longer recommended anyway, but it's not deprecated yet either - #779 may change that. The issue here isn't how Marshmallow behaves, but that it isn't obvious.
Actual behaviour:
Preferred, works: fields.List(fields.Nested(Child()))
Old style with nested class, works: fields.Nested(Child, many=True)
Old style with nested instance, broken: fields.Nested(Child(), many=True)
When trying the nested instance way, the error you get is unhelpful because it's the result of Marshmallow treating the nested schema as singular:
{'_schema': ['Invalid input type.']}
Confusing things even further, many and a nested instance seem to work when dumping (even though it shouldn't), but not when loading (as described). Since the broken way half works, I'm sure there will be code out there that relies on it.
Pull request to follow.
The text was updated successfully, but these errors were encountered:
mmulqueen
added a commit
to mmulqueen/marshmallow
that referenced
this issue
May 3, 2022
I discovered the hard way that fields.Nested silently ignores the many parameter when it's passed an instance. It's my fault, I can see in the docstring that this behaviour is described, but that didn't stop me wasting a load of time debugging the error. I see that using many=True is no longer recommended anyway, but it's not deprecated yet either - #779 may change that. The issue here isn't how Marshmallow behaves, but that it isn't obvious.
Actual behaviour:
Preferred, works:
fields.List(fields.Nested(Child()))
Old style with nested class, works:
fields.Nested(Child, many=True)
Old style with nested instance, broken:
fields.Nested(Child(), many=True)
When trying the nested instance way, the error you get is unhelpful because it's the result of Marshmallow treating the nested schema as singular:
Confusing things even further, many and a nested instance seem to work when dumping (even though it shouldn't), but not when loading (as described). Since the broken way half works, I'm sure there will be code out there that relies on it.
Pull request to follow.
The text was updated successfully, but these errors were encountered: