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

Creating and including a related object returns trimmed numbers with relationJoins #24414

Open
TheMC47 opened this issue Jun 4, 2024 · 0 comments · May be fixed by prisma/prisma-engines#4961
Assignees
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. kind/bug A reported bug. topic: floating point types Topic related to floating point types and precision loss topic: relationJoins

Comments

@TheMC47
Copy link

TheMC47 commented Jun 4, 2024

Bug description

With relationJoins enabled, if you crate an object with another related object and include their values, the floats of the related object will be truncated:

    const created = await prisma.main.create({
        data: {
            other: {
                create: {
                    num: 1.23456789101112131415161718192, 
                },
            },
        },
        include: {
            other: true,
        },
    });

And this has nothing to do with the accuracy, since fetching the object directly doesn't cause this issue:


    const other = created.other[0];

    const otherDB = await prisma.other.findUniqueOrThrow({
        where: {
            id: other.id,
        },
    });
    expect(other.num).toEqual(otherDB.num); // <-- doesn't work

How to reproduce

Explained in https://github.com/TheMC47/prisma-bug-report:

  1. Create an object and a related object in the same query, returning them both
  2. Fetch the created object
  3. Compare the floats

For the test case included in the repo:

 FAIL  ./test.spec.ts
  ✕ Test (49 ms)

  ● Test

    expect(received).toEqual(expected) // deep equality

    Expected: 1.234568
    Received: 1.2345679

      26 |         },
      27 |     });
    > 28 |     expect(other.num).toEqual(otherDB.num);
         |                       ^
      29 | });
      30 |

      at test.spec.ts:28:23
      at fulfilled (test.spec.ts:5:58)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        0.335 s, estimated 1 s
Ran all test suites.

Expected behavior

They're the same

Prisma information

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

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

model main {
  id    Int     @id @default(autoincrement())
  other other[]
}

model other {
  id      Int   @id @default(autoincrement())
  main_id Int?
  num     Float @db.Real
  main    main? @relation(fields: [main_id], references: [id], onDelete: NoAction, onUpdate: NoAction)
}
import { PrismaClient } from "@prisma/client";

test("Test", async () => {
    const prisma = new PrismaClient({
        log: ["error", "info", "query", "warn"],
    });

    const created = await prisma.main.create({
        data: {
            other: {
                create: {
                    num: 1.23456789101112131415161718192,
                },
            },
        },
        include: {
            other: true,
        },
    });

    const other = created.other[0];

    const otherDB = await prisma.other.findUniqueOrThrow({
        where: {
            id: other.id,
        },
    });
    expect(other.num).toEqual(otherDB.num);
});

Environment & setup

  • OS: Manjaro Linux
  • Database: PostgreSQL 13
  • Node.js version: 18.19.1

Prisma Version

Environment variables loaded from .env
prisma                  : 5.15.0
@prisma/client          : 5.15.0
Computed binaryTarget   : debian-openssl-3.0.x
Operating System        : linux
Architecture            : x64
Node.js                 : v18.19.1
Query Engine (Node-API) : libquery-engine 12e25d8d06f6ea5a0252864dd9a03b1bb51f3022 (at node_modules/@prisma/engines/libquery_engine-debian-openssl-3.0.x.so.node)
Schema Engine           : schema-engine-cli 12e25d8d06f6ea5a0252864dd9a03b1bb51f3022 (at node_modules/@prisma/engines/schema-engine-debian-openssl-3.0.x)
Schema Wasm             : @prisma/prisma-schema-wasm 5.15.0-29.12e25d8d06f6ea5a0252864dd9a03b1bb51f3022
Default Engines Hash    : 12e25d8d06f6ea5a0252864dd9a03b1bb51f3022
Studio                  : 0.501.0
Preview Features        : relationJoins
@TheMC47 TheMC47 added the kind/bug A reported bug. label Jun 4, 2024
@janpio janpio added topic: relationJoins bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. topic: floating point types Topic related to floating point types and precision loss domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. labels Jun 4, 2024
@Weakky Weakky self-assigned this Jun 5, 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. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. kind/bug A reported bug. topic: floating point types Topic related to floating point types and precision loss topic: relationJoins
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants