-
-
Notifications
You must be signed in to change notification settings - Fork 620
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
Allow setting a global unknown setting #1367
Comments
You can modify the base schema's from marshmallow import Schema, fields, EXCLUDE
Schema.Meta.unknown = EXCLUDE
class Test(Schema):
foo = fields.Str()
Test().load({'foo': 'test', 'junk': 2})
# {'foo': 'test'} |
Indeed, that's just as simple. Perhaps this could be added to the docs? |
I'm not sure this would fit well in the "Handling Unknown" section of the quick start docs. Global configuration doesn't seem to have a dedicated place in the docs either. It would probably be useful to mention the pattern in the upgrading docs. Feature requests that are solved by applying Python language features to documented implementation details do come up regularly though. I wonder if the examples folder would be a good place to put some of these patterns? |
I don't think we need to add any additional API for setting defaults. I think many users use a base class that defines their defaults. I guess we can the suggestion above to the docs, but is it really a pattern we want to encourage? Feel free to send a PR adding the docs, but closing the issue since the use case has been met. |
Yeah, that's what I was thinking. We could make it clear that it's just a stopgap. |
Right, new users shouldn't need this, because they can easily make a custom base class. |
Well, the point about documenting it is that it becomes a supported use case that should be tested. Either way, this is simple enough that it can stay as is. Let me know what you think, happy to spin up a quick PR. |
I'm not convinced this is something that should be tested. It's a stopgap, after all, so I don't think it's something we want to guarantee support for. Secondly, it's just using "plain Python", i.e. it's not really a marshmallow feature. |
Being able to configure |
This will only be applicable in that file. I want to use it as a global configuration(In other files too). |
I don't think so. Did you check that ? Since |
Yeah crosschecked |
It should work. Could you please provide a repro case? |
The new
RAISE
unknown setting can make the migration pretty painful, especially for those who are just fine withEXCLUDE
ing unknown keys. What about making this global default a configuration setting?Something as simple as:
I know it's possible to subclass
Schema
, but that seems more heavy-handed.The text was updated successfully, but these errors were encountered: