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.

Make fields deserialization more strict ?

See original GitHub issue

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

github_iconTop GitHub Comments

1reaction
stefanoborinicommented, Feb 5, 2018

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.

0reactions
sloriacommented, Sep 22, 2015

Good catch @density . Will fix shortly.

Read more comments on GitHub >

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

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