1602 / 1602/jugglingdb

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

Offen
#342 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
JavaScript
Sterne
2k
Forks
238
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, node.js
Bereich
backend, databases
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.