Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-obvious error when using fields.Nested with schema instance and many #1982

Open
mmulqueen opened this issue May 3, 2022 · 0 comments
Open

Comments

@mmulqueen
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant