From 936ddfb9c68edb44c76fc36cf251415c0828d266 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Fri, 11 Oct 2019 12:28:30 -0400 Subject: [PATCH] fix(update): handle subdocument pre('validate') errors in update validation Fix #7187 --- lib/document.js | 8 +++++--- lib/helpers/updateValidators.js | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/document.js b/lib/document.js index 0183ce47e51..b816b8bde97 100644 --- a/lib/document.js +++ b/lib/document.js @@ -1932,9 +1932,11 @@ Document.prototype.validate = function(options, callback) { options = null; } - return utils.promiseOrCallback(callback, cb => this.$__validate(options, function(error) { - cb(error); - }), this.constructor.events); + return utils.promiseOrCallback(callback, cb => { + this.$__validate(options, function(error) { + cb(error); + }); + }, this.constructor.events); }; /*! diff --git a/lib/helpers/updateValidators.js b/lib/helpers/updateValidators.js index 199ef0677f7..de8b027bb9f 100644 --- a/lib/helpers/updateValidators.js +++ b/lib/helpers/updateValidators.js @@ -136,6 +136,9 @@ module.exports = function(query, schema, castedDoc, options, callback) { _err.path = updates[i] + '.' + key; validationErrors.push(_err); } + } else { + err.path = updates[i]; + validationErrors.push(err); } } callback(null);