Skip to content

Commit

Permalink
fix: backport #14743
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Jul 12, 2024
1 parent 378d115 commit 3f21bfa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -3113,6 +3113,11 @@ Model.$__insertMany = function(arr, options, callback) {
const throwOnValidationError = typeof options.throwOnValidationError === 'boolean' ? options.throwOnValidationError : false;
const lean = !!options.lean;

const asyncLocalStorage = this.db.base.transactionAsyncLocalStorage?.getStore();
if ((!options || !options.hasOwnProperty('session')) && asyncLocalStorage?.session != null) {
options = { ...options, session: asyncLocalStorage.session };
}

if (!Array.isArray(arr)) {
arr = [arr];
}
Expand Down
5 changes: 5 additions & 0 deletions test/docs/transactions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ describe('transactions', function() {
}();
assert.equal(doc.name, 'test_transactionAsyncLocalStorage');

await Test.insertMany([{ name: 'bar' }]);

throw new Error('Oops!');
}),
/Oops!/
Expand All @@ -468,6 +470,9 @@ describe('transactions', function() {

exists = await Test.exists({ name: 'foo' });
assert.ok(!exists);

exists = await Test.exists({ name: 'bar' });
assert.ok(!exists);
});
});
});

0 comments on commit 3f21bfa

Please sign in to comment.