7.6.0 Overridden Validate methode not called
See original GitHub issueHi, just upgraded from 7.5.2 to 7.6.0 and now behaviour is changed. Overridden ‘Validate’ is not called anymore. The validator is applied with ‘SetCollectionValidator’ and ‘SetValidator’.
Why override? To validate tree structure DTO object for example. Via property chain any errors are reported as a path in the tree. ‘Childs[2].Childs[0].Prop’.
Is this not supported anymore?
public class FooValidator : AbstractValidator<Foo>
{
public override ValidationResult Validate(ValidationContext<Foo> ctx)
{
// Create ValidationResult
// Use InstanceToValidate in ctx
// Modify PropertyChain in ctx
// Add erros to validation result
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
7.6.0 Overridden Validate methode not called · Issue #774
Hi, just upgraded from 7.5.2 to 7.6.0 and now behaviour is changed. Overridden 'Validate' is not called anymore. The validator is applied ...
Read more >c# - Validate not called in custom validator
The issue is that when I post the form, the Validate override is not called on the view model validator, so the reusable...
Read more >15.11 Creating and Using a Custom Validator - Java ...
This method validates the input and also accesses the custom error messages to be displayed when the String is invalid. The validate method...
Read more >7. Validation, Data Binding, and Type Conversion
We're going to provide validation behavior for the Person class by implementing the following two methods of the org.springframework.validation.Validator ...
Read more >Active Record Validations
As you can see, our validation lets us know that our Person is not valid without a name attribute. The second Person will...
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
Thanks, I should have some time on Friday to look into this.
This is now fixed, and I’ve released 7.6.100 - please download it and give it a try.
Some background information if you’re interested:
Every property validator has a flag called
IsAsync
that indicates whether it can be run asynchronously. Child validators have this marked as true as they can contain async validators of their own.Prior to 7.6, if you call
ValidateAsync
on the root validator, then all property validators that are marked withIsAsync
are run asynchronously, and then all validators without this flag are run synchronously. However, if you calledValidate
on the root validator, all child validators were run synchronously.A fix for a separate issue changed the behaviour of
Validate
so that if a child validator supports async validation, it synchronusly calls its ValidateAsync. Because child validators do support being called asynchrously, this behaviour took priority over the non-async method.The fix was to improve the async check to only run async methods when the root validator was called Asynchronously.