-
-
Notifications
You must be signed in to change notification settings - Fork 603
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]: transactions in AWS RDS Data API not working #1171
Comments
For more details see drizzle-team#1171
Thanks, I'm hitting this hard as well. |
Me too. Did you find a workaround @NachoVazquez? |
Yeah, I forked the repo and created a release from this PR. It is working 🙃 Once this get merge I will get back to the original package. |
Sharing an alternative workaround that does not require forking the codebase. Monkey-patch import { AwsDataApiPreparedQuery, AwsDataApiSession } from 'drizzle-orm/aws-data-api/pg';
/**
* Patches the AWS Data API driver to fix transactions
* @see https://github.com/drizzle-team/drizzle-orm/issues/1171
*/
function patchAwsDataApiDriver() {
AwsDataApiSession.prototype.prepareQuery = function (
query,
fields,
name,
customResultMapper
) {
return new AwsDataApiPreparedQuery(
this.client,
query.sql,
query.params,
query.typings ?? [],
this.options,
fields,
this.transactionId,
customResultMapper
);
};
} |
Good stuff! |
How do you use it @pantoninho ? Do you call it before using drizzle? Like in a folder |
There are a lot of ways to use it, but I suggest the following:
import { RDSDataClient } from '@aws-sdk/client-rds-data';
import {
AwsDataApiPreparedQuery,
AwsDataApiSession,
drizzle
} from 'drizzle-orm/aws-data-api/pg';
import { PgDatabase } from 'drizzle-orm/pg-core';
import { patchAwsDataApiDriver } from './aws-data-api-patch.js';
/**
* @type {PgDatabase}
*/
const db = getAWSDataApiClient();
export { db };
/**
* Returns a drizzle client for an RDS database.
* @returns {import('drizzle-orm/aws-data-api/pg').AwsDataApiPgDatabase} the drizzle client
*/
function getAWSDataApiClient() {
patchAwsDataApiDriver();
const rdsClient = new RDSDataClient({});
return drizzle(rdsClient, {
database,
resourceArn,
secretArn
});
} |
Yeah, thank you, that's what I had in mind! |
What version of
drizzle-orm
are you using?0.28.2
What version of
drizzle-kit
are you using?0.19.12
Describe the Bug
I'm using the AWS RDS Data API (yes I know), but transactions are not working. I.e. rollback does not work. The reason is that everything runs outside the transaction.
I've tried to come up with a simple sample, basically a select in a transaction, and it seems the transactionId is not correctly passed:
What happens is that this calls prepareQuery in
src/aws-data-api/pg/session.ts
, buttransacationId
is always null. So that is this code:I can fix this by changing the transactionId parameter in the call that creates a new
AwsDataApiPreparedQuery
to bethis.transactionId
. Then everything is fine.If you look at other session examples, you can see that the third parameter is called
name
, for example insrc/pg-core/session.ts
, nottransactionId
:The code is pretty complex, but as far as I can see it
transactionId
is never passed in, so a clear bug. If you look atexecute
insrc/pg-core/query-builders/select.ts
you see that it always calls_prepare()
without any parameters:But
_prepare
needs a name, as that should end up as the transactionId above:As you see above, that third parameter is
transactionId
insession.prepareQuery
, but is undefined. It cannot possibly have a transactionId the way the code is written.I suggest
prepareQuery
in session gets changed to get thesessionId
from itself, then everything works.Expected behavior
Rollback works
Environment & setup
No response
The text was updated successfully, but these errors were encountered: