1602 / 1602/jugglingdb

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

Abierto
#342 1 comentario 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
JavaScript
Estrellas
2k
Forks
238
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript, node.js
Área
backend, databases
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.