Skip to content

Commit

Permalink
Fix: Added missing call to _reject in Transactor#transaction (#3706)
Browse files Browse the repository at this point in the history
  • Loading branch information
briandamaged committed Mar 7, 2020
1 parent 6e6b666 commit d00bd8d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
8 changes: 1 addition & 7 deletions lib/transaction.js
Expand Up @@ -275,13 +275,7 @@ function makeTransactor(trx, connection, trxClient) {
return trxClient.transaction(container, options, trx);
} else {
return new Promise((resolve, _reject) => {
trxClient.transaction(
(nestedTrx) => {
resolve(nestedTrx);
},
options,
trx
);
trxClient.transaction(resolve, options, trx).catch(_reject);
});
}
};
Expand Down
21 changes: 21 additions & 0 deletions test/integration/builder/transaction.js
Expand Up @@ -728,4 +728,25 @@ module.exports = function(knex) {
).to.be.rejected;
});
});

it('handles promise rejections in nested Transactions (#3706)', async function() {
const fn = sinon.stub();
process.on('unhandledRejection', fn);
try {
await knex.transaction(async function(trx1) {
// These two lines together will cause the underlying Transaction
// to be rejected. Prior to #3706, this rejection would be unhandled.
const trx2 = await trx1.transaction(undefined, {
doNotRejectOnRollback: false,
});
await trx2.rollback();

await expect(trx2.executionPromise).to.have.been.rejected;
});

expect(fn).have.not.been.called;
} finally {
process.removeListener('unhandledRejection', fn);
}
});
};

0 comments on commit d00bd8d

Please sign in to comment.