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.

Replacing `Arg(dict)` with marshmallow?

See original GitHub issue

In webargs < 0.16, I have arguments defined as Arg(dict, ...). How do I convert these to marshmallow fields? The changelog shows examples with strings and nested arguments, but I couldn’t find an example with dict.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
sloriacommented, Mar 22, 2016

@stranbird That is the expected behavior; fields.Dict does not expect to receive strings as input, and webargs does not do any special preprocessing. One solution is to create a custom field:

class JSONDict(fields.Dict):

    def _deserialize(self, value):
        if isinstance(value, str):
            value = json.loads(value)
        super()._deserialize(value)

@use_args({
  'where': JSONDict()
})
0reactions
yuanfeizcommented, Mar 23, 2016

@sloria neat solution, ty!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fields — marshmallow 3.19.0 documentation
Allows you to replace nested data with one of the data's fields. ... kwargs (dict) – Field-specific keyword arguments. Returns:.
Read more >
Python Marshmallow: Dict validation Error - Stack Overflow
This is just toy data but exemplifies that the keys in the dictionaries are not fixed, they change in number and text. So...
Read more >
marshmallow - Read the Docs
To customize the error message for required fields, pass a dict with a required key as the error_messages argument for the field. class...
Read more >
Object validation and conversion with Marshmallow in Python
Marshmallow is a Python library that converts complex data types to and ... Note: To avoid installing packages globally, use the virtual ...
Read more >
marshmallow -- simplified object serialization | We all are data.
To customize the error message for required fields, pass a dict with a required key as the error_messages argument for the field. from...
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