From 76f92d287133de47642744f3404598fd12046d45 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Tue, 3 Dec 2024 11:25:53 -0500 Subject: [PATCH] fix: avoid throwing error if saveOptions undefined when invalidating subdoc cache Fix #15062 --- lib/plugins/saveSubdocs.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/plugins/saveSubdocs.js b/lib/plugins/saveSubdocs.js index 6dc0cc9e2e..bb88db59f8 100644 --- a/lib/plugins/saveSubdocs.js +++ b/lib/plugins/saveSubdocs.js @@ -27,8 +27,10 @@ module.exports = function saveSubdocs(schema) { cb(err); }); }, function(error) { - // Bust subdocs cache because subdoc pre hooks can add new subdocuments - _this.$__.saveOptions.__subdocs = null; + // Invalidate subdocs cache because subdoc pre hooks can add new subdocuments + if (_this.$__.saveOptions) { + _this.$__.saveOptions.__subdocs = null; + } if (error) { return _this.$__schema.s.hooks.execPost('save:error', _this, [_this], { error: error }, function(error) { next(error);