post_dump is passing a list of objects as original object
See original GitHub issueHi,
I think post_dump with pass_original=True should pass the original object related to the data serialized and not a list of objects which this object belongs to.
from marshmallow import fields, post_dump, Schema
class DeviceSchema(Schema):
id = fields.String()
@post_dump(pass_original=True)
def __post_dump(self, data, obj):
print(obj) # <-- this is a list
devices = [dict(id=1), dict(id=2)]
DeviceSchema().dump(devices, many=True)
In the above example, the parameter obj
is a list of devices rather than the device object itself.
What do you think?
Issue Analytics
- State:
- Created 8 years ago
- Reactions:3
- Comments:9 (8 by maintainers)
Top Results From Across the Web
r - How to get the original name of a object when sending a list ...
The problem is that the return_name function described in your answer will return "datasets" and not the actual, original object name. r.
Read more >11. Lists — How to Think Like a Computer Scientist
A list is an ordered collection of values. The values that make up a list are called its elements, or its items. We...
Read more >Java is Pass by Value, Not Pass by Reference | DigitalOcean
This helps to show that Java is pass by value, since the swap() method only acts upon copies of the original object reference...
Read more >Classes - Object-Oriented Programming in Python
A class is a kind of data type, just like a string, integer or list. ... on an object, the object itself is...
Read more >Do you generally send objects or their member variables into ...
In the first version, the UI code is blindly passing the data object and it's up to ... Methods with excessively long argument...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Since schema validators are designed to validate a single object instance unless
pass_many
is explicitlytrue
, I think the intuitive behavior is forpass_original
to return the corresponding original object instance unlesspass_many
is explicitlytrue
.Edit:
false
->true
+1 for @viniciuschiele’s points. It is unexpected to receive a list instead of an object.