We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
How can we chain Marshmallow hooks when you use schema inheritance?
Marshmallow
Suppose the following "dumb" example:
from marshmallow import Schema, fields, post_load class PersonSchema(Schema): name = fields.Str() @post_load def post_load(self, data, **_): data["name"] = data["name"].capitalize() return data class EmployeeSchema(PersonSchema): title = fields.Str() @post_load def post_load(self, data, **_): data["title"] = data["title"].upper() return data EmployeeSchema().load({"name": "john", "title": "ceo"}) # {"name": "john", "title": "CEO"}
In this example, only the subclassed hook was triggered. How do you make the parent hook trigger as well on deserialization, in this case?
The text was updated successfully, but these errors were encountered:
This is not specific to marshmallow, but a Python issue. The child class overrides post_load method. Give it another name.
post_load
class PersonSchema(Schema): name = fields.Str() @post_load def capitalize(self, data, **_): data["name"] = data["name"].capitalize() return data class EmployeeSchema(PersonSchema): title = fields.Str() @post_load def upper(self, data, **_): data["title"] = data["title"].upper() return data
Note the order is not guaranteed (#600).
Sorry, something went wrong.
No branches or pull requests
How can we chain
Marshmallow
hooks when you use schema inheritance?Suppose the following "dumb" example:
In this example, only the subclassed hook was triggered. How do you make the parent hook trigger as well on deserialization, in this case?
The text was updated successfully, but these errors were encountered: