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.

post_dump is passing a list of objects as original object

See original GitHub issue

Hi,

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:closed
  • Created 8 years ago
  • Reactions:3
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
deckar01commented, Aug 27, 2019

Since schema validators are designed to validate a single object instance unless pass_many is explicitly true, I think the intuitive behavior is for pass_original to return the corresponding original object instance unless pass_many is explicitly true.

  • Picking the original preprocessed object out of a list is inconvenient at best and impossible at worst.
  • Validation of a nested list is more appropriate on a parent schema instead of an overload of the child schema validator.

Edit: false -> true

2reactions
frolcommented, Mar 6, 2016

+1 for @viniciuschiele’s points. It is unexpected to receive a list instead of an object.

Read more comments on GitHub >

github_iconTop 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 >

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