proposal: changing fields.Field's `**metadata` to `metadata=None`
See original GitHub issueThis is backward incompatible change.
pros
typo check is working correctly.
Sometimes, people that unfamiliar with marshmallow, want to add validation with typo.
e.g.
class S(Schema):
# this is typo. (correct keyword is `validate`)
v = fields.Integer(validator=validate.Range(max=10))
Current marshmallow’s fields.Field implementation is such as like below.
class Field(FieldABC):
def __init__(self, default=missing_, attribute=None, load_from=None, dump_to=None,
error=None, validate=None, required=False, allow_none=None, load_only=False,
dump_only=False, missing=missing_, error_messages=None, **metadata):
pass
So, above typo is also valid schema definition. adding Range validator as metadata, and validation on deserialization is working without error when passing invalid data.
Sometimes, sometimes, the code such like this is passed our code review, then we are disappointed ours poor heads(this is careless human error).
But, if, metadata is just keyword argument(metadata=None
), this typo-ed code is raising TypeError.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:6 (4 by maintainers)
Top Results From Across the Web
RETS Change Proposal 3: Global Structure Information
This proposal adds several fields to the RETS 1.0 metadata specification to allow a client to find and exploit relationships between resources offered...
Read more >What Are the Different Types of Metadata Fields in DAM?
What are metadata fields and are you using the appropriate metadata fields to optimize your DAM system? We dive into the different types...
Read more >Importing metadata from a spreadsheet onto existing documents
To check which fields are present and to add new fields, select any document and go to the Info tab. Click Edit Metadata...
Read more >Object metadata | Cloud Storage - Google Cloud
This page discusses the commonly-used metadata fields that are stored along with ... There are two categories of metadata that users can change...
Read more >Deploy and Organize Metadata Using Unlocked Packages
Dreamforce 2018 - Developer Track. Deploy and Organize Metadata Using Unlocked Packages. 1.7K views 4 years ago. Salesforce Developers.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @podhmo for the suggestion.
You raise a fair point–the current way does run the risk of passing invalid kwargs.
My worry is that we’ll be breaking lots of use cases. apispec and webargs, for example, both make use of
metadata
to add new field params not offered by marshmallow. Passing metadata as this way also allows users to add their own field kwargs. For example, I suggested usingmetadata
to add akey
parameter here: https://github.com/marshmallow-code/marshmallow/pull/714#issuecomment-355451867I’ll have to think more about the tradeoffs with this one.
Closing this for now, as I don’t think we’ll add it in the near future. I’m open to the
allowed_field_metadata
idea, but I don’t think it warrants the added complexity at this point.