question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

proposal: changing fields.Field's `**metadata` to `metadata=None`

See original GitHub issue

This 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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sloriacommented, Jan 5, 2018

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 using metadata to add a key parameter here: https://github.com/marshmallow-code/marshmallow/pull/714#issuecomment-355451867

I’ll have to think more about the tradeoffs with this one.

0reactions
sloriacommented, Jan 10, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found