`InteractiveTransaction`: Middleware param `runInTransaction` set to `false`
See original GitHub issueBug description
When using interactiveTransaction
preview feature alongside with a middleware you won’t get the runInTransaction
parameter set to true
.
Despite the above issue I would want the ability to have access to the transactionPrismaClient
or an afterCommit
hook in params
. That way I can run logic only after the transaction is committed.
Sequelize equivalent of this would be: https://sequelize.org/master/manual/transactions.html#the--code-aftercommit--code--hook
How to reproduce
// schema.prisma
generator client {
provider = "prisma-client-js"
previewFeatures = ["interactiveTransactions"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Car {
model String
}
// middleware.ts
export const middleware = (prisma: PrismaClient) => {
prisma.$use(async (params, next) => {
console.log('params', params) // params.runInTransaction = false -> should be true
})
}
// prisma.ts
import { middleware } from './middleware'
const prisma = new PrismaClient()
middleware(prisma)
export { prisma }
// main.js
import { prisma } from './prisma.ts'
const main = async () => {
await prisma.$transaction(async (tPrisma) => {
return tPrisma.car.create({ data: { model: 'abc' } })
})
}
Expected behavior
No response
Prisma information
in How to reproduce
I wrote an example
Environment & setup
- OS: Ubuntu
- Database: PostgreSQL
- Node.js version: Node v14
Prisma Version
prisma : 2.29.1
@prisma/client : 2.29.1
Current platform : debian-openssl-1.1.x
Query Engine : query-engine 1be4cd60b89afa04b192acb1ef47758a39810f3a (at node_modules/@prisma/engines/query-engine-debian-openssl-1.1.x)
Migration Engine : migration-engine-cli 1be4cd60b89afa04b192acb1ef47758a39810f3a (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine : introspection-core 1be4cd60b89afa04b192acb1ef47758a39810f3a (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary : prisma-fmt 1be4cd60b89afa04b192acb1ef47758a39810f3a (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash : 1be4cd60b89afa04b192acb1ef47758a39810f3a
Studio : 0.419.0
Preview Features : interactiveTransactions
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Prisma Client API (Reference)
If the query returns NotFoundError , then the API will not roll back any operations in the array of calls. As a workaround,...
Read more >Prisma 3.10.0 Release - GitClear
... Middleware param runInTransaction set to false ... Interactive transaction: Sequential Prisma Client operations timeout but work when ...
Read more >Returning value from runInTransaction() In Android Room ...
Query that I have: If all the queries in the transaction are successful, then I want to return an image object that needs...
Read more >9 JDBC Data Source Transaction Options - Oracle Help Center
This chapter provides information on XA, non-XA, and Global Transaction options for WebLogic data sources in WebLogic Server 12.1.3. When you configure a...
Read more >documentation - CUBA Platform. Developer's Manual
When nullable = false JPA ensures that the field has a value when saved. ... runInTransaction() - execute an action in a new...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @millsp and @janpio
It is fixed indeed. I must have missed a step, or had another error as now it is working as expected.
Hey @kevinmamaqi we have an example reproduction for this https://github.com/prisma/prisma/blob/93cecb2a4cbd0db3127cafc5880d4708407c7b12/packages/client/src/__tests__/integration/happy/interactive-transactions-sqlite/test.ts/#L400-L419