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.

method field is not called

See original GitHub issue

Why the method field is not called when loading a dict?

from marshmallow import Schema, fields

class UserSchema(Schema):
    first_name = fields.Str(load_from='name')
    email = fields.Email()
    custom = fields.Method('yo')

    def yo(self, obj):
        return 'custom'

schema = UserSchema()
result = schema.load({'name': 'j', 'email': 'j@j.jom'})
print result.data # prints {'first_name': u'j', 'email': u'j@j.jom'}   

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
norbertpycommented, Feb 29, 2016

Never mind. It’s only called when dumping not loading. But why?

0reactions
brettdhcommented, Mar 8, 2016

To elaborate: I needed to use the deserialize kwarg to Method() to get what I wanted, and the field had to be present to get processed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DRF SerializerMethodField not getting called - Stack Overflow
In the response I'm getting only the bg_colors field. The other field is absent from response, and its get_field method is also not...
Read more >
Function field method is not called for tree view - Odoo
Hello, I have a function field in a tree view that is supposed to display a calculated field, but for some reason the...
Read more >
How to create custom model fields - Django documentation
All of Django's fields (and when we say fields in this document, we always mean model fields and not form fields) are subclasses...
Read more >
Fields - C# Programming Guide | Microsoft Learn
A field in C# is a variable of any type that is declared directly in a class or struct. Fields are members of...
Read more >
Class Fields, Constructors, and Methods
method that can tell you the student's name when calling the method.) - Now, let's take a look at a declaration of a...
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