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.

RFC: Return deserialized data when strict=True

See original GitHub issue

Status quo

load currently returns a namedtuple (UnmarshalResult) containing both the deserialized data and error messages.

from marshmallow import Schema, fields, ValidationError

class UserSchema(Schema):
    id = fields.Int(required=True)

    class Meta:
        strict = True


schema = UserSchema()
try:
    result = schema.load({'id': 42})
except ValidationError as e:
    print(e.messages)
assert result.data['id'] == 42

Proposed API

When strict=True, return only the deserialized data. Messages can already be accessed from ValidationError.messages.

from marshmallow import Schema, fields, ValidationError

class UserSchema(Schema):
    id = fields.Int(required=True)

    class Meta:
        strict = True


schema = UserSchema()
try:
    data = schema.load({'id': 42})
except ValidationError as e:
    print(e.messages)
assert data['id'] == 42

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
maximkulkincommented, Mar 10, 2017

@douglas-treadwell I vote not to do that. Once Marshmallow goes this route, there are plenty of option combinations to introduce as a new methods: loaddata(), loadmany(), loadstrictmany()

@sloria I would rather opt to deprecate strict option at all and just do validation error exceptions all the time. Then load() could return just data in an nonconfusing way

4reactions
douglas-treadwellcommented, Mar 10, 2017

I am in favor of strict=True by default, but I think the API for load() returning different KINDS of data depending on configuration might be confusing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Upgrading to Newer Releases — marshmallow 3.19.0 ...
In marshmallow 2, python-dateutil was used to deserialize RFC or ISO 8601 datetimes if it was installed. In marshmallow 3, datetime deserialization is...
Read more >
marshmallow - Read the Docs
In short, marshmallow schemas can be used to: • Validate input data. • Deserialize input data to app-level objects. • Serialize app-level objects...
Read more >
json — JSON encoder and decoder — Python 3.11.1 ...
If the data being deserialized is not a valid JSON document, a JSONDecodeError will be raised. Changed in version 3.6: s can now...
Read more >
json - Why does deserializeUntyped interpret Strings starting ...
Perhaps the RFC specifies that number parsing discards unrecognised trailing characters, hence your result? Try out:
Read more >
Serialization error in SAP Web Service. - SAP Community
Hi all, I have exposed a custom RFC as a Web Service. This is a simple web service that returns Customer Data (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