Skip to content

Commit e8aa787

Browse files
committed
fix(client): prevent nested BEGIN in sequential transaction by forcing transaction context
1 parent 7a2316c commit e8aa787

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

packages/orm/src/client/client-impl.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ export class ClientImpl {
127127
});
128128
}
129129

130-
if (baseClient?.isTransaction && !executor) {
131-
// if we're creating a derived client from a transaction client and not replacing
132-
// the executor, reuse the current kysely instance to retain the transaction context
133-
this.kysely = baseClient.$qb;
130+
if (baseClient?.isTransaction) {
131+
// preserve transaction context in derived clients: reuse the kysely instance when
132+
// no new executor is provided, or create a Transaction (not plain Kysely) when one is
133+
this.kysely = executor ? new Transaction(this.kyselyProps) : baseClient.$qb;
134134
} else {
135135
this.kysely = new Kysely(this.kyselyProps);
136136
}
@@ -638,7 +638,9 @@ function createModelCrudHandler(
638638
const rootZenExecutor = (client as unknown as ClientImpl).kyselyProps
639639
.executor as ZenStackQueryExecutor;
640640
contextExecutor = rootZenExecutor
641-
.withConnectionProvider({ provideConnection: (consumer) => rawExecutor.provideConnection(consumer) })
641+
.withConnectionProvider({
642+
provideConnection: (consumer) => rawExecutor.provideConnection(consumer),
643+
})
642644
.withQueryContext(queryContext);
643645
}
644646

0 commit comments

Comments
 (0)