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.

Load Nested field with only=str gives error when sent flat data structure instead of dictionary

See original GitHub issue

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

github_iconTop GitHub Comments

1reaction
erlingbocommented, Oct 29, 2015

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 the pk 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.

0reactions
sloriacommented, Jan 8, 2017

This is the same issue addressed in #316. Further discussion should happen there.

Read more comments on GitHub >

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

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