-
-
Notifications
You must be signed in to change notification settings - Fork 631
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
Warnings and errors for incompatible use of schema instance and many in fields.Nested #1983
base: dev
Are you sure you want to change the base?
Conversation
…r on deserialisations. marshmallow-code#1982
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution and sorry about the delay.
I understand the issue. Yet I'm reluctant to add code just to warn about this specific case.
I left a few comments anyway. I might change my mind and accept the test at init. No strong opinion against it.
if self.many and not self.schema.many: | ||
raise FieldConfigurationError( | ||
'"many" may not be used in conjunction with an instance in a nested field.' | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd remove this test. This should be coverered by the init warning you added above, right?
many = self.schema.many or self.many | ||
if many and not utils.is_collection(value): | ||
raise self.make_error("type", input=value, type=value.__class__.__name__) | ||
# Check whether many on the nested field and the schema are in conflict. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this comment was meant for the change above?
warnings.warn( | ||
'Passing "many" is ignored if using an instance of a schema. Consider fields.List(fields.Nested(...)) instead.', | ||
FieldConfigurationWarning, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd remove the suggestion.
#779 lists other unexpected edge cases like this. I would rather bite the bullet and deprecate |
Addresses the issue I've described in #1982. Behaviour should be unchanged, but more obvious.