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.

Nested in Nested post args not working as expected.

See original GitHub issue

Not sure how to display this properly so here it is:

https://pastebin.com/GUAxc98c

I am parsing post args for a POST request as follows:

post_args = {
  'item_1': input_fields.Str(),
  'item_2': input_fields.Str(), 
  'item3: input_fields.Nested({
      '0.00': input_fields.Nested({'someItem': input_fields.Str(), ... }),
       '0.10': input_fields.Nested({'someItem': input_fields.Str(), ... }),
       '0.20': input_fields.Nested({'someItem': input_fields.Str(), ... })
  })
}

When parsed I expect to get the following:

parsed_args = {
  'item1' : 'some string', 
  'item2': 'some other string',
  'item3': { 
     '0.00': {'someItem': 'some useful string'},
     '0.10': {'someItem': 'some useful string'},
     '0.20': {'someItem': 'some useful string'}
  }
}

But instead it puts item3 nested values into a dictionary with key 0 and then the nested items as follows:

parsed_args = {
  'item1' : 'some string', 
  'item2': 'some other string',
  'item3': { 
     '0': {
           '0.00': {'someItem': 'some useful string'},
           '0.10': {'someItem': 'some useful string'},
           '0.20': {'someItem': 'some useful string'}
      }
  }
}

Am I doing something wrong? Am I missing anything ? Is this supposed to happen?

I can confirm that the data received in JSON are in the right structure.

Any ideas?

Update I ve noticed this happens when the keys are strings of decimals i.e 0.00 0.10 0.20 but still why can’t I do that?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lafrechcommented, Apr 7, 2020

I’m afraid my workaround above will work and the issue is the dot in the input data.

Related marshmallow issue : https://github.com/marshmallow-code/marshmallow/issues/1506.

1reaction
lafrechcommented, Apr 7, 2020

Looks like this is due to marshmallow interpreting the dot in the decimal string as a subpath delimiter.

I’m not sure this behaviour is correct, so it might be a bug.

You might be able to circumvent it by setting a name without dot and using attribute/data_key to get back your dotted name, but that’s not ideal.

Untested code:

- '0.00': input_fields.Nested({'someItem': input_fields.Str(), ... })
+ '000': input_fields.Nested({'someItem': input_fields.Str(), ... }, attribute="0.00", data_key="0.00")
Read more comments on GitHub >

github_iconTop Results From Across the Web

POST Request with nested arguments - Stack Overflow
Basically, in HTTP there is no 'nesting' of parameters per se. ... not (at least not "natively") is multiple values for query parameters....
Read more >
Nested params option not works as expected #2534 - GitHub
Describe the bug Nested params option not works as expected. ... POST requests take in the data on the body, data in axios'...
Read more >
Working with nested data - Splunk Documentation
Extract a nested map from one field and add it to another field · Prepare the body field so that it can be...
Read more >
Nested bash if then else script not working as expected to ...
To use wildcards when passing arguments to the script, don't quote the wildcard: script "John's file*.mp4" -> script "John's file"*.mp4 .
Read more >
Prisma Client API (Reference)
You must re-generate the Prisma Client each time you add or rename a data source. ... User" AS "t0" INNER JOIN "public". ......
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