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.

7.6.0 Overridden Validate methode not called

See original GitHub issue

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

github_iconTop GitHub Comments

1reaction
JeremySkinnercommented, Jun 6, 2018

Thanks, I should have some time on Friday to look into this.

0reactions
JeremySkinnercommented, Jun 7, 2018

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 with IsAsync are run asynchronously, and then all validators without this flag are run synchronously. However, if you called Validate 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.

Read more comments on GitHub >

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

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