Parallel validation error thrown in post validate hook if re-validating #8597
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Do you want to request a feature or report a bug?
bug
What is the current behavior?
I just recently upgraded from 5.8.4 to 5.9, and the new Parellel validation error that was added in 5.8.5 is causing issues with some functionality I have.
When calling
this.validate
in a post validate hook, a Parallel validation error will be thrown. My guess is becausethis.$__.validating
must still be set while the hook is running.I'm not sure if this would be the desired behavior, what do you think? Perhaps the way I am writing the functionality would be better done another way, but I hadn't really thought of one.
If the current behavior is a bug, please provide the steps to reproduce.
Given a schema:
For theoretical purposes similar to mine, let's say employeeNumber must be retrieved from an external API. This is how I have done it:
In my case, it isn't ideal to fetch this data if the other fields are invalid, because it's just going to get thrown out anyway, which is why I am doing it in a post validate hook. But I need to handle the case where if something about the returned employee number is invalid, which is why validation would need to be repeated.
What is the expected behavior?
A document should be able to be re-validated in a post('validate') hook
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node 10.16.0
Mongoose 5.9.0
Mongodb 4.0.6
The text was updated successfully, but these errors were encountered: