Load Nested field with only=str gives error when sent flat data structure instead of dictionary
See original GitHub issueWhen using a schema with the only attribute set to a string, the load method returns UnmarshalResult without errors nor data.
class MySchema(Schema):
class Meta:
fields = ('pk',)
pk = fields.String()
MySchema(only='pk').load('an_id1234')
MySchema(only='pk').load({'pk': 'an_id1234'})
Both return the same UnmarshalResult
UnmarshalResult(data={}, errors={})
Preferably the first should work, but the second could be used with a pre load method on the schema class.
Is there anything I have done wrong or is this a bug?
Note: I use the same schema for dumping data an thus use only='pk'
and not only=('pk',)
for getting the correct dump output
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
WTForms: FieldList of FormField can't load nested data
I did some debugging and found that WTForms while loading the document's data in to the form searches for 'locations-0-location' but MultiDict() ...
Read more >How to access nested data in Python - Towards Data Science
In this short guide you will learn how you can access data that is deeply nested in python's lists and dictionary data structures....
Read more >Guile Reference Manual - GNU.org
Contributors to this Manual. Like Guile itself, the Guile reference manual is a living entity, cared for by many people over a long...
Read more >Changelog — pytest documentation
#10190: Invalid XML characters in setup or teardown error messages are now ... pytest now shows the differing field names (possibly nested) instead...
Read more >PyOxidizer - Release 0.23.0 Gregory Szorc
Scan the filesystem for Python resources (source modules, bytecode files, package resources, distribution meta- data, etc) and turn them into ...
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
Okei. I’ll try to explain. I’ll want a dump that gives me a file (json or yaml) and then be able to load the file again later.
I want the relations to be flat, just using the primary key of the object it links to. This feature is documented here as
only='pk'
When I try to load the file using the same schema I get an error
UnmarshalResult(data={'pk': 123}, errors={'child': {u'_schema': [u'Invalid input type.']}})
If I use
only=('pk',)
the dumped relations will not be flat and include an object with thepk
as attribute. E.g.{'pk': 123, 'child': {'pk': u'456'}}
vs what I want: ``{‘pk’: 123, ‘child’: u’456’}`I need to integrate with other teams, and the files need to be as human readable as possible, thus I want the flat structure. When this is a documented feature of the Nested field, I also expect it to be able to load the corresponding data.
This is the same issue addressed in #316. Further discussion should happen there.