Hello, I've got an issue with transactions I don't...
# prisma-client
l
Hello, I've got an issue with transactions I don't know how to pinpoint. I basically compare 2 sets of data (outside of transaction), and spit out 3 groups of data - entities to update, entities to delete and to create.. In order to maintain some kind of consistency between previous and new data, I'Ve decided to put them in interactive transaction, like so
Copy code
await prisma.$transaction(async (prisma) => {
  for (const entity of changed) {
    await prisma.entity.update({
      where: ...
      data: ...
    })
  }
  if (deleted.length) {
  	// soft delete
    await prisma.entity.updateMany({
      where: ...,
      data: {
        deleted: true,
      }
    })
  }
  if (created.length) {
    await prisma.entity.createMany({
      data: created,
    })
  }
  logResult(...)
})
The transaction itself works (it's used this way in many different entities and they pass alright), but in a few that seem to run much longer than other, I'm getting an exception:
PrismaClientKnownRequestError: Transaction API error: Transaction already closed: Transaction is no longer valid. Last state: 'Expired'.
What can I do about it, or what causes it?
Apparently
$transaction()
has second parameter with options
maxWait
and
timeout
with
timeout
having default
5s
... Upping the timeout worked 👍
🙌 1