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.

Remove validation on serialization

See original GitHub issue

When 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:closed
  • Created 5 years ago
  • Comments:17 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
sloriacommented, Jul 17, 2019

Probably not? handle_error is meant for handling ValidationError, which we’re proposing should only get raised on deserialization.

2reactions
sloriacommented, Jul 16, 2019

Should we get rid of the code that rewrites the errors in _serialize()? If we aren’t going to pack the errors into the same data structure as load(), should we let the first error bubble to the top uninterrupted?

Yes, that’s what I’m proposing.

Read more comments on GitHub >

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

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