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

upsert() not working when trying to update a DateTime with a higher precision than configured #18833

Open
Bassadin opened this issue Apr 19, 2023 · 0 comments
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. tech/engines/query engine Issue in the Query Engine topic: dates / DateTime topic: upsert()

Comments

@Bassadin
Copy link

Bug description

When I tried to upsert a timestamp (example: 2023-04-02T10:13:25.915541Z) into my PostgreSQL DB (whose DateTime field uses a default precision of 3), I ran into a unique constraint that I had set for the field.
The inserting beforehand worked (when there wasn't a value there).

More info (with a slightly more bloated prisma and code example) can be found in this thread.

How to reproduce

  1. See Schema and code further down.
  2. The first run (create) works
  3. The second run (expected: do nothing) fails. Because Prisma seems to still try to insert the value (that Postgres seemingly rounded).

Expected behavior

Expected to upsert the value as expected (maybe with a rounded value)

Prisma information

model ModelName {
    id                  Int                  @id @default(autoincrement())
    timestamp           DateTime             
    deviceId            String

    @@unique([deviceId, timestamp])
}

Code:

 await this.prisma.modelName.upsert({
    where: {
        deviceId_timestamp: {
            deviceId: "1",
            timestamp: "2023-04-02T10:13:25.915541Z",
        },
    },
    create: {
        deviceId: "1",
        timestamp: "2023-04-02T10:13:25.915541Z",
    },
    update: {},
});

Environment & setup

  • OS: Windows
  • Database: PostgreSQL
  • Node.js version: v18.15.0

Prisma Version

4.12.0
@Bassadin Bassadin added the kind/bug A reported bug. label Apr 19, 2023
@Weakky Weakky added team/client Issue for team Client. tech/engines/query engine Issue in the Query Engine bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. topic: dates / DateTime topic: upsert nested upsert labels Apr 21, 2023
@janpio janpio added topic: upsert() and removed topic: upsert nested upsert labels Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. tech/engines/query engine Issue in the Query Engine topic: dates / DateTime topic: upsert()
Projects
None yet
Development

No branches or pull requests

3 participants