-
Notifications
You must be signed in to change notification settings - Fork 156
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
New undefined parameter action: Warn #212
base: master
Are you sure you want to change the base?
Conversation
Thanks for implementing this and submitting another PR! I've been thinking about this one. I think this functionality is useful and different flavors of it have been requested in other issues / PRs (#223, #207, maybe others). However, I'm not sure this should be nested under the existing the if undefined_parameter_action == Undefined.WARN:
# mm has no warn implementation, so we resolve to ignore
undefined_parameter_action = Undefined.EXCLUDE In addition to it no longer mirroring marshmallow's parameters, I think it's worth considering whether it couples two unrelated things: Rather, I think this functionality should be part of a unified API for configuring warnings / validations / etc. In fact, the specification of this configuration may not even be an individual class-level thing (i.e. here it's specified as a kwarg to the class decorator). As a user, I imagine I would generally want warnings either on or off fat a global-level. Perhaps I might even dynamically switch them on when I'm using a certain external API, then off. There's a potential argument to add That said, I think a lot of the code in your PR can be repurposed to be configured by the global config. Let me know what you think, and just want to say I appreciate your contributions again! |
I see your concerns, and I want to make an argument and a suggestion how to get both things: In order to get fine grained control as well as be able to set in on the global level, I'd suggest to use something like |
This pull requests adds a 4th possible
Undefined
action:Undefined.WARN
.When using this action, a RuntimeWarning is issued for undefined parameters,
otherwise it behaves the same as
Undefined.EXCLUDE
.Because marshmallow does not have this option available, we default back to
EXCLUDE
when usingschema()
.I updated the README to include:
You can issue a
RuntimeWarning
for undefined parameters by setting theundefined
keyword toUndefined.WARN
(WARN
as a case-insensitive string works as well). Note that you will not be able to retrieve them usingto_dict
:I've also cleaned up the test cases for undefined parameters a bit (grouped them by the action that they test and gave them more descriptive names). So don't worry if the diff for the test case file is large, I've just moved stuff around more or less and added tests for
WARN
.@lidatong