Make fields deserialization more strict ?
See original GitHub issueWorking with the library, it appears to me that the deserialization module has a lack of strictness from my point of view:
class DocSchema(Schema):
str = fields.String()
bool = fields.Boolean()
# Ok, None is not implicitly acceptable
DocSchema().load({'str': None, 'bool': None})
# UnmarshalResult(data={}, errors={'str': ['Field may not be null.'], 'bool': ['Field may not be null.']})
# But it's not the case for numbers
DocSchema().load({'str': 42, 'bool': 42})
# UnmarshalResult(data={'str': '42', 'bool': True}, errors={})
# Or for any complex structure (list, dict)
DocSchema().load({'str': {}, 'bool': {}})
# UnmarshalResult(data={'str': '{}', 'bool': False}, errors={})
Is there a way to enforce real strict validation ? Passing a dict as argument of a string field without getting any error sounds like a silent fail for me…
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
How can I have more flexible serialization and ...
Is there a serialization library or some way that I can have deserialization be less strict, like if there is an extra field...
Read more >Deserialization - OWASP Cheat Sheet Series
Deserialization is the reverse of that process, taking data structured from some format, and rebuilding it into an object. Today, the most popular...
Read more >Upgrading to Newer Releases — marshmallow 3.19.0 ...
Email and fields.URL only validate input upon deserialization. They do not validate on serialization. This makes them more consistent with the other fields...
Read more >Matt's Tidbits #9 — Be careful with JSON deserialization
Jackson has support for a “strict parsing mode”, which will throw an exception during parsing if the POJO does not exactly match the...
Read more >Deserialize History record with read-only fields?
My solution to this problem was to create json test data, and then deserialize the data into history records, or at least sObjects....
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
We are facing a similar lack of strictness with a String field that, when presented with a tuple, converts it into a string and stores it as such. We would like to guarantee that no repr() conversion takes place, and only legitimate strings go in the field.
Good catch @density . Will fix shortly.