Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transaction method resolves if the provided callback rejects with undefined. #6065

Open
dmitrysteblyuk opened this issue Apr 29, 2024 · 0 comments

Comments

@dmitrysteblyuk
Copy link

Environment

Knex version: 3.1.0
Database + version: posgtres 14.2
OS: MacOS 13.5.1

Bug

  1. Explain what kind of behaviour you are getting and how you think it should do

When a transaction callback rejects with undefined, the transaction promise is resolved.

await knex.transaction(() => Promise.reject());
console.log('No failure.');

I think the expected behavior should be promise rejection, because in JavaScript exceptions (and promise rejection reasons) can be of any type (including undefined).

  1. This happens because we pass undefined to transaction.rollback() here:
    .catch((err) => {
    return transactor.rollback(err);
    });

And if doNotRejectOnRollback enabled (it is by default) and the passed error is undefined, we do resolve:

if (value === undefined) {
if (this.doNotRejectOnRollback && /^ROLLBACK\b/i.test(sql)) {
this._resolver();
return;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant