RFC: Return deserialized data when strict=True
See original GitHub issueStatus 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:
- Created 7 years ago
- Reactions:3
- Comments:10 (7 by maintainers)
Top 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 >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
@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. Thenload()
could return just data in an nonconfusing wayI 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.