1602 / 1602/jugglingdb

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

オープン
#342 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
JavaScript
スター
2k
フォーク
238
PR マージ指標
30日以内にマージされた PR はありません

説明

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.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, node.js
領域
backend, databases
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。