fields.Nested should optionally pass the parent object to the Nested Schema
See original GitHub issueAs described in #900, there is no obvious way to create a nested serialization from a flat object. To fix this, fields.Nested
should accept an optional from_parent
argument. When true, the nested Schema is passed the parent object rather than the attribute at the field name. from_parent
will default to False
, which will maintain current behavior.
Any feedback on this idea? I plan on implementing it soon.
Thanks, James
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:12 (7 by maintainers)
Top Results From Across the Web
Nesting Schemas — marshmallow 3.19.0 documentation
Schemas can be nested to represent relationships between objects (e.g. ... Use a Nested field to represent the relationship, passing in a nested...
Read more >Marshmallow serialize nested with parent field - Stack Overflow
In marshmallow it's possible to pass values from a parent scheme to its children before serialization by using the pre_dump decorator on the ......
Read more >Nested field type | Elasticsearch Guide [8.5] | Elastic
The nested type is a specialised version of the object data type that allows arrays of objects to be indexed in a way...
Read more >marshmallow - Bountysource
To fix this, fields.Nested should accept an optional from_parent argument. When true, the nested Schema is passed the parent object rather than the ......
Read more >Nested - OpenSearch documentation
By default, each of the nested objects is dynamically mapped as object field type. Any object field can take an array of objects....
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
I also solved this using a (simpler) variant of @m-a-choquette’s method:
This let me use this schema:
(ignore my custom fields, they’re not important for this example)
Which transforms:
into
aka, a valid response (or segment thereof) under the JSON API standard!
Hi, It feels a little weird to set a property on the object while serializing it.
To work around this, we did something like this:
Each Section field receives the full object.