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.

data_key parameter not working

See original GitHub issue

As I understand the docs, I could use the data_key param if the name of the field is not the same as the key name in the dict.

data_key (str) – The name of the key to get the value from when deserializing. If None, assumes the key has the same name as the field.

However, this does not work for me. The your_name field is not loaded from the dict. If I change the key to name it gets loaded and the data objects now has a key your_name. That is not what I expected based on the documentation. I am using marshmallow==2.19.2.

>>> from marshmallow import Schema, fields
>>> class FooLoad(Schema):
...     name = fields.Str(data_key='your_name')
... 
>>> schema_load = FooLoad()
>>> schema_load.load({'your_name': 'qwertz'})
UnmarshalResult(data={}, errors={})
>>> schema_load.load({'name': 'qwertz'})
UnmarshalResult(data={'your_name': 'qwertz'}, errors={})

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
lafrechcommented, Jun 15, 2019

Both attribute and data_key are used for both serialization and deserialization. They are just at the opposite end of the chain.

Object ------------- Field ------------- Serialized dict attribute ------------------------------- data_key (or field name) -------------------- (or field name)

0reactions
kristian-lindincommented, Jun 17, 2019

Thanks for such nice and fast replies 😃!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Need help with gridview datakeys parameter! - MSDN - Microsoft
The problem is that parameters in your datasource must be types that resolve to equivalent sql types. You are attempting to bind to...
Read more >
DataKeyNames coming up as undesired Update parameters ...
I am using the DataKeys for lookup purposes but I don't need them in my update ... -in-a-typed-dataset-shouuld-not-update-primary-key.
Read more >
How to pass a Datakey values into parameters in telerik grid
HI I need to pass my datakey value into parameter of .Ajax.Delete() here is my Code can anyone help me to get out...
Read more >
How to assign new values to ActionContextParameters ...
Question. Hello,. is it possible to assign new values to ActionContextParameters/DataKeys inside the execute(event) function of an action?
Read more >
Scheduled import fails with error "Unable to import data. Key ...
Can't update record, one step is failing with error: Unable to import data. Key cannot be null. Parameter name: key CSM 7.0.2, 8.0.2,...
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