Allow callables for fields.Nested
See original GitHub issueSuggested earlier here: https://github.com/marshmallow-code/marshmallow/issues/19#issuecomment-43685498.
The suggestion would be to allow:
foo = fields.Nested(lambda: Foo)
in addition to
foo = fields.Nested('Foo')
Seems a bit cleaner in general.
Issue Analytics
- State:
- Created 8 years ago
- Comments:36 (32 by maintainers)
Top Results From Across the Web
Nesting Schemas — marshmallow 3.19.0 documentation
If you have two objects that nest each other, you can pass a callable to Nested . This allows you to resolve order-of-declaration...
Read more >How to use the marshmallow.fields.Nested function in ... - Snyk
To help you get started, we've selected a few marshmallow.fields.Nested examples, based on popular ways it is used in public projects.
Read more >2.3. Defining documents — MongoEngine 0.24.2 documentation
MongoEngine allows you to define schemata for documents as this helps to reduce coding errors, and allows for utility methods to be defined...
Read more >Python Inner Functions: What Are They Good For?
Inner functions, also known as nested functions, are functions that you define inside other functions. In Python, this kind of function has direct...
Read more >Call functions from your app | Cloud Functions for Firebase
The Cloud Functions for Firebase client SDKs let you call functions directly ... With callables, Firebase Authentication tokens, FCM tokens, and App Check ......
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
Reopening this because I think this would enable valid use cases that are currently unmet.
(1) Passing arbitrary arguments to the nested Schema (only
many
,exclude
, andonly
are currently supported. This could solve https://github.com/marshmallow-code/marshmallow/issues/285#issuecomment-152577723.(2) With a slight modification to the OP’s proposed API, users could easily implement a polymorphic nested field.
Feedback welcome.
Not in marshmallow currently, but it is a schema syntax I have been investigating. Also, https://github.com/justanr/marshmallow-annotations/issues/5.
Back on track: I don’t think
Method
andFunction
are viable substitutes for a completeNested
field. The suggested workaround is not something I would expect developers to discover on their own or something I would want to document. Strings work well and are easy to document/use for recursively schema references. If a callable is needed for more complex behavior, a custom field is probably the best tool for the job.