Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@updateAt is not updated when create and update in same transaction. #22326

Open
charagaki opened this issue Dec 9, 2023 · 1 comment
Open
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/regression A reported bug in functionality that used to work before. team/client Issue for team Client. topic: transaction topic: updatedAt

Comments

@charagaki
Copy link

charagaki commented Dec 9, 2023

Bug description

When create and update in same transaction, a column with @updateAt is not updated in update timing.

This behavior is not appeared in prisma 4.3.0.
It's appeared in prisma 4.4.0 or later versions.

I execute prisma.user.create({}) and prisma.user.update({}) in same interactiveTransactions.
It has 4-seconds wait time between create and update.

However, the value of a column with @updateAt is the same as the value of a column with @default(now()).

id      caption     createdAt                           updatedAt
100     mod         2023-12-09 15:35:15.970 +0900       2023-12-09 15:35:15.970 +0900

I checked some issues.
I'm not sure but following issue and PR might to be related my issue.

#12572
prisma/prisma-engines#3200

How to reproduce

  1. Run migrations and generate a prisma client
  2. run following source code
  3. Check the createdAt column and updatedAt column

Expected behavior

Same result as prisma 4.3.0.

updatedAt is updated when the record is updated.

id      caption     createdAt                           updatedAt
100     mod         2023-12-09 16:00:38.516 +0900       2023-12-09 16:00:42.527 +0900

The value of updatedAt is delayed by about 4 seconds.

Prisma information

generator client {
  provider = "prisma-client-js"
  previewFeatures = ["interactiveTransactions"]
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
  id        String      @id @default(uuid())
  caption   String?      
  createdAt DateTime?   @default(now()) @map("created_at") @db.Timestamptz(3)
  updatedAt DateTime?   @updatedAt @map("updated_at") @db.Timestamptz(3)

  @@map("user")
}
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

const execute = async () => {
  return await prisma.$transaction(async (prisma) => {
    const mili = new Date().getMilliseconds();

    await prisma.user.create({
      data: { id: `${mili}` },
    });
    await new Promise((resolve) => setTimeout(resolve, 4000));

    await prisma.user.update({
      data: { caption: `mod` },
      where: { id: `${mili}` },
    });
  });
};

execute()
  .catch((e) => {
    throw e;
  })
  .finally(async () => {
    await prisma.$disconnect();
  });

Environment & setup

  • OS: macOS 13.3.1
  • Database: PostgreSQL 14.6
  • Node.js version: 16.20.0

Prisma Version

prisma                  : 5.7.0
@prisma/client          : 5.7.0
Computed binaryTarget   : darwin-arm64
Operating System        : darwin
Architecture            : arm64
Node.js                 : v16.20.0
Query Engine (Node-API) : libquery-engine 79fb5193cf0a8fdbef536e4b4a159cad677ab1b9 (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Schema Engine           : schema-engine-cli 79fb5193cf0a8fdbef536e4b4a159cad677ab1b9 (at node_modules/@prisma/engines/schema-engine-darwin-arm64)
Schema Wasm             : @prisma/prisma-schema-wasm 5.7.0-41.79fb5193cf0a8fdbef536e4b4a159cad677ab1b9
Default Engines Hash    : 79fb5193cf0a8fdbef536e4b4a159cad677ab1b9
Studio                  : 0.495.0
@charagaki charagaki added the kind/bug A reported bug. label Dec 9, 2023
@jkomyno jkomyno added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. topic: transaction topic: updatedAt team/client Issue for team Client. labels Dec 11, 2023
@janpio janpio added kind/regression A reported bug in functionality that used to work before. and removed kind/bug A reported bug. labels Dec 11, 2023
@apolanc apolanc added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. and removed bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. labels Jan 31, 2024
@SevInf SevInf self-assigned this Feb 2, 2024
@SevInf
Copy link
Contributor

SevInf commented Feb 2, 2024

Can confirm the issue.
Internal link for reproduction

@SevInf SevInf added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/regression A reported bug in functionality that used to work before. team/client Issue for team Client. topic: transaction topic: updatedAt
Projects
None yet
Development

No branches or pull requests

5 participants