RFC: Change the way we store metadata?
See original GitHub issueUsers are often bit by the fact that fields store arbitrary keyword arguments as metadata. See https://github.com/marshmallow-code/marshmallow/issues/683.
…The reasons we use **kwargs instead of e.g.
metadata=
are mostly historical. The original decision was that storing kwargs 1) was more concise and 2) saved us from having to come up with an appropriate name… “metadata” didn’t seem right because there are use cases where the things your storing aren’t really metadata. At this point, it’s not worth breaking the API.
Not the best reasons, but I think it’s not terrible. We’ve discussed adding a whitelist of metadata keys in the past, but we decided it wasn’t worth the added API surface.
_Originally posted by @sloria in https://github.com/marshmallow-code/marshmallow/issues/779#issuecomment-522283135_
Possible solutions:
- Use
metadata=
. - Specify a whitelist of allowed metadata arguments.
Feedback welcome!
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (10 by maintainers)
Top GitHub Comments
That issue is rather specific to the marshmallow-dataclass, and I think the benefits still outweigh the cost. It is much better to have a proper exception get raised when a user passes an invalid keyword argument rather than passing silently.
https://stackoverflow.com/questions/5644836/in-python-how-does-one-catch-warnings-as-if-they-were-exceptions