{ if: 'fieldName } doesn't play nice with async validations
- Lingua principale
- JavaScript
- Stelle
- 2k
- Fork
- 238
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
When using the `if` option on an async validation, the async `isValid` does not call the callback.
Example User model:
```
User.validateAsync({
if : 'createdByScript',
message : 'group is not valid'
}, validateGroup);
function validateGroup(err, done) {
Group.find(this.groupId, function (error, group) {
if (error || !group) { err(); }
done();
});
}
```
The following code does not call the isValid callback:
```
var u = new User();
u.isValid(function (valid) {
// This is never executed.
});
```
One could argue it's unnecessary to have this attribute on a custom async validation because the properties could be checked within the validation method (which is what I ended up doing to get around the issue), but it should then be ignored or at least documented so people are aware.
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
Look at the async validation logic in the ORM's validation module, likely in lib/validations.js or similar. The issue is that the 'if' option prevents the async validation callback from being invoked. Start by tracing the isValid method and how it handles conditional async validations. Write a test to reproduce the bug, then ensure the callback is called when the condition is met.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, node.js
- Ambito
- backend, databases
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 45/100