Skip to content
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

Method Fields and Context? #355

Open
Makiyu-py opened this issue Jul 21, 2021 · 0 comments
Open

Method Fields and Context? #355

Makiyu-py opened this issue Jul 21, 2021 · 0 comments

Comments

@Makiyu-py
Copy link

Kind of like what marshmallow's context-aware serialization has:

class PersonSchema(Schema):
    id = fields.Integer()
    name = fields.Method("get_name")

    def get_name(self, person, context):
        if context.get("anonymize"):
            return "<anonymized>"
        return person.name


person = Person(name="Monty")
schema = PersonSchema()
schema.dump(person)  # {'id': 143, 'name': 'Monty'}

# In a different context, anonymize the name
schema.context["anonymize"] = True
schema.dump(person)  # {'id': 143, 'name': '<anonymized>'}

but with asynchronous methods (depending on the driver)

It would be very useful to have this feature here on uMongo too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant