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.

Add ability to exclude specific fields from fields.Dict during de-/serialization

See original GitHub issue

Some data structures are semi-defined, sitting in-between fields.Dict() and fields.Nested(). It would be helpful to be able to exclude specific fields by name from de-/serialization

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
deckar01commented, May 20, 2018

Only knowing the fields you want to exclude seems like an unusual use case. I would not recommend adding this functionality into the core Dict field. The nicer syntax you are looking for could be accomplished by subclassing Dict.

class BlacklistedDict(fields.Dict):
    def __init__(self, blacklist, **kwargs):
        super(BlacklistedDict, self).__init__(**kwargs)
        self.blacklist = blacklist

    def _serialize(self, value, attr, obj):
        value = super(BlacklistedDict, self)._serialize(value, attr, obj)
        return {key: value[key] for key in value if key not in self.blacklist}

    def _deserialize(self, value, attr, obj):
        value = super(BlacklistedDict, self)._deserialize(value, attr, obj)
        return {key: value[key] for key in value if key not in self.blacklist}
0reactions
trautcommented, May 20, 2018

@lafrech I can but property in fields.Dict constructor would be much prettier, hence this request

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to exclude specific fields on serialization with jsonpickle?
I'm using SQLAlchemy extension with Flask. While serializing my models (which are also used for database operations) ...
Read more >
Serializers - Django REST framework - Tom Christie
We'll declare a serializer that we can use to serialize and deserialize Comment objects. ... The first part of serializer class defines the...
Read more >
marshmallow.schema — marshmallow 3.19.0 documentation
May be an `OrderedDict`. - ``exclude``: Tuple or list of fields to exclude in the serialized result. Nested fields can be represented with...
Read more >
great_expectations.marshmallow__shade.schema
exclude – Blacklist of the declared fields to exclude when instantiating the Schema. If a field appears in both only and exclude ,...
Read more >
marshmallow - Read the Docs
You can also exclude fields by passing in the exclude parameter. 4.2.3 Deserializing ... receives a dictionary of deserialized data as its only...
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