Skip to content

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

@TheMC47

Description

@TheMC47

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

Metadata

Metadata

Assignees

Labels

bug/1-unconfirmedBug should have enough information for reproduction, but confirmation has not happened yet.domain/clientIssue in the "Client" domain: Prisma Client, Prisma Studio etc.kind/bugA reported bug.topic: floating point typesTopic related to floating point types and precision losstopic: relationJoins

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions