1602 / 1602/jugglingdb

{ if: 'fieldName } doesn't play nice with async validations

Ouverte
#342 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
JavaScript
Étoiles
2k
Forks
238
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
javascript, node.js
Domaine
backend, databases
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Clairement spécifiée
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.