Remove validation on serialization
See original GitHub issueWhen using Dict(values=Nested())
I expect errors in dictionary values to be nested in such a way that I can locate exactly what element is causing the problem. This seems to work as expected for load()
, but not for dump()
.
Minimal example:
- Marshmallow version: 3.0.0rc4
- Python version: 3.7.2
from marshmallow import Schema, ValidationError, fields
class InnerSchema(Schema):
x = fields.Int()
class OuterSchema(Schema):
inner = fields.Dict(keys=fields.Str(), values=fields.Nested(InnerSchema))
foo = {"inner": {"some-key": {"x": "abc"}}}
try:
OuterSchema().load(foo)
except ValidationError as e:
print(e)
# >>> {'inner': defaultdict(<class 'dict'>, {'some-key': {'value': {'x': ['Not a valid integer.']}}})}
# Very helpful - and what I expect
class Inner:
def __init__(self, x):
self.x = x
class Outer:
def __init__(self, inner):
self.inner = inner
bar = Outer(inner={"some-key": Inner(x="abc")})
try:
OuterSchema().dump(bar)
except ValidationError as e:
print(e)
# >>> {'inner': {'x': ['Not a valid integer.']}}
# Surprisingly - 'some-key' and 'value' are not present here,
# which makes it harder to pinpoint the problem in large objects
Issue Analytics
- State:
- Created 5 years ago
- Comments:17 (15 by maintainers)
Top Results From Across the Web
In Django's rest framework, how do I turn off validation for ...
So you can remove the validation in (at least) two ways,. Method-1. Remove validations by extra_kwargs - (DRF doc) Meta class attribute
Read more >Validation-and-Serialization - Fastify
Treat the schema definition as application code. Validation and serialization features dynamically evaluate code with new Function() , which is not safe to...
Read more >Validators - Django REST framework
In these cases you may want to disable the automatically generated validators, by specifying an empty list for the serializer Meta.validators attribute.
Read more >Validation and Serialization in Fastify v3 - DEV Community
This article will explain all you need to know to master the new validation and serialization with Fastify v3!
Read more >Model Validation in ASP.NET Web API - Microsoft Learn
If you have used model validation in ASP.NET MVC, this should look familiar. The Required attribute says that the Name property must not...
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
Probably not?
handle_error
is meant for handlingValidationError
, which we’re proposing should only get raised on deserialization.Yes, that’s what I’m proposing.