File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -626,8 +626,22 @@ function createModelCrudHandler(
626626 // Bind queryContext to the executor so onKyselyQuery hooks can read it.
627627 // Uses txClient's executor (which holds the tx connection) when in a transaction.
628628 const baseClient = txClient ?? client ;
629- const baseExecutor = ( baseClient . $qb as any ) . getExecutor ( ) as ZenStackQueryExecutor ;
630- const contextExecutor = baseExecutor . withQueryContext ( queryContext ) ;
629+ const rawExecutor = ( baseClient . $qb as any ) . getExecutor ( ) ;
630+
631+ let contextExecutor : ZenStackQueryExecutor ;
632+ if ( rawExecutor instanceof ZenStackQueryExecutor ) {
633+ contextExecutor = rawExecutor . withQueryContext ( queryContext ) ;
634+ } else {
635+ // Kysely wraps the real executor in NotCommittedOrRolledBackAssertingExecutor
636+ // inside sequential transactions — delegate connection to rawExecutor so
637+ // queries run within the transaction.
638+ const rootZenExecutor = ( client as unknown as ClientImpl ) . kyselyProps
639+ . executor as ZenStackQueryExecutor ;
640+ contextExecutor = rootZenExecutor
641+ . withConnectionProvider ( { provideConnection : ( consumer ) => rawExecutor . provideConnection ( consumer ) } )
642+ . withQueryContext ( queryContext ) ;
643+ }
644+
631645 const contextClient = ( baseClient as unknown as ClientImpl ) . withExecutor (
632646 contextExecutor ,
633647 ) as unknown as ClientContract < any > ;
You can’t perform that action at this time.
0 commit comments