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

[BUG]: AWS Data API nested transactions - savepoints #1936

Closed
hugo082 opened this issue Feb 28, 2024 · 0 comments
Closed

[BUG]: AWS Data API nested transactions - savepoints #1936

hugo082 opened this issue Feb 28, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@hugo082
Copy link
Contributor

hugo082 commented Feb 28, 2024

What version of drizzle-orm are you using?

0.29.3

What version of drizzle-kit are you using?

No response

Describe the Bug

To implement nested transactions, drizzle creates savepoints - here.

It appear that the savepoints queries are executed with the savepoint name as parameter which is not supported by AWS Data API (or at least seems to be, I haven't found the confirmation).

// succeeds
aws rds-data execute-statement --resource-arn $RESOURCE --secret-arn $SECRET --database $DB --sql "BEGIN;
    INSERT INTO test VALUES ('a');
    SAVEPOINT sp1;
    INSERT INTO test VALUES ('b');
    ROLLBACK TO SAVEPOINT sp1;
    INSERT INTO test VALUES ('c');
COMMIT;"

// fails
aws rds-data execute-statement --resource-arn $RESOURCE --secret-arn $SECRET --database $DB --sql "BEGIN;
    INSERT INTO test VALUES ('a');
    SAVEPOINT :1;
    INSERT INTO test VALUES ('b');
    ROLLBACK TO SAVEPOINT :1;
    INSERT INTO test VALUES ('c');
COMMIT;" --parameters '[{"name":"1","value":{"stringValue":"sp1"}}]'

You can easily repro via:

await db.transaction(async (trx) => {
  console.log('before trx2')

  await trx.transaction(async (trx2) => { // <= query `savepoint sp1;` fails
    console.log('in trx2')
  });

  console.log('after trx2')
});

savepoints open/close

I noticed that the creation & release/rollback of the savepoints are not awaited - here. It produce a strange behavior were we entre inside the nested transaction block even if the transaction creation failed.
In the example above it means that the 3 logs are executed & 2 unhandled promise rejections are created (queries savepoint sp1; & release savepoint sp1;).
Is it intentional?

Expected behavior

The following code succeeds:

await db.transaction(async (trx) => {
  console.log('before trx2')

  await trx.transaction(async (trx2) => {
    console.log('in trx2')
  });

  console.log('after trx2')
});

Environment & setup

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants