Skip to content

v41.0.0

Compare
Choose a tag to compare
@github-actions github-actions released this 17 Apr 15:54
· 107 commits to main since this release

New Slonik behavior means that you can no longer accidentally run a non-transaction query inside of a transaction.

If you receive an error UnexpectedForeignConnectionError, then you are trying to execute a query using a connection that is not associated with the transaction. This error is thrown to prevent accidental unsafe transaction handling, e.g.

connection.transaction(async (transactionConnection) => {
  await connection.query(sql.typeAlias('void')`INSERT INTO foo (bar) VALUES ('baz')`);
});

In this example, the query is executed using the connection that is not associated with the transaction. This is unsafe because the query is not part of the transaction and will not be rolled back if the transaction is aborted.

This behavior is achieved using AsyncLocalContext.