Schema validators can only report a single issue.
See original GitHub issueSome times surfacing multiple validation issues with the data is necessary. For example in this case (implementation of pairwise is omitted):
from marshmallow import Schema, fields, validates_schema, ValidationError
class NumberSchema(Schema):
number = fields.Integer()
class ListSchema(Schema):
data = fields.Nested(NumberSchema, many=True)
@validates_schema(pass_many=True)
def validate_numbers(self, data, many):
if not many:
return
for i, (n1, n2) in enumerate(pairwise(data)):
if n1 >= n2:
raise ValidationError('this number must be smaller than the previous one', '{}.number'.format(i+1))
if the list of numbers has multiple issues, only the first encountered issue is reported. This is sometimes not ideal for user interfaces (the user would appreciate all issues displayed at once).
I would suggest to allow validators return a list of ValidationError
to indicate multiple issues.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to Fix Schema Validation Errors
The most common schema validation error is "either "offers", "review", or "aggregate rating" should be specified." Here's how to fix it.
Read more >How do I avoid Schema Validation Errors in my e-filed returns ...
A schema validation error is an error in the required formatting of the electronic file established by the taxing authority which can be...
Read more >Understanding schema errors | HESA
Schema errors prevent the validation being run in full because the file cannot be read. This means that errors cannot be traced to...
Read more >Validate() behavior not consistent with documetnation
Problem : The mongo documentation explains schema validation and the ... The output of the validate function would then theoretically report ...
Read more >Cannot validate recursive schema - json - Stack Overflow
There are a few issues, so let's walk through deriving this schema one step at a time. Let's start with the object representation...
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
After reading this discussion, I set out to try solve this myself. I implemented a POC function
Which did what I wanted it to, provided I called
ValidationError
like this:This has a terrible interface, but my use case required it…
But, whilst finishing off writing my validation errors, I noticed the docstring for
ValidationError
specifies that you can actually provide a tuple or list of field of where to apply the message specified as the first argument ofValidationError
So without any extra code, I got this working by using
I hope this clears things up for anyone looking here in the future.
@zhaostu This is a long struggle between me and library authors (See this issue and this pullrequest).
At my current work we needed support for this advanced validation, so I did table flip and now we use my fork of Marshmallow with all features WE need.
Also, I decided to start my own validation library - lollipop - pretty much similar to marshmallow but IMO does some things better. It still misses some planned features but already meets our needs, so I recommend giving it a try.