question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`InteractiveTransaction`: Middleware param `runInTransaction` set to `false`

See original GitHub issue

Bug description

When using interactiveTransaction preview feature alongside with a middleware you won’t get the runInTransaction parameter set to true.

image

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:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kevinmamaqicommented, May 23, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found