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

relationJoins MySQL converts nested Decimal to float #23233

Closed
michaelhays opened this issue Feb 21, 2024 · 3 comments · Fixed by prisma/prisma-engines#4771
Closed

relationJoins MySQL converts nested Decimal to float #23233

michaelhays opened this issue Feb 21, 2024 · 3 comments · Fixed by prisma/prisma-engines#4771
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/engines Issue for tech Engines. topic: floating point types Topic related to floating point types and precision loss topic: joins topic: relationJoins
Milestone

Comments

@michaelhays
Copy link

michaelhays commented Feb 21, 2024

Bug description

When using relationLoadStrategy: 'join' in MySQL, retrieving nested models with Decimal fields seem to convert decimal values to floats.

How to reproduce

https://github.com/michaelhays/prisma-relationjoins-decimal

See these lines for what gets logged.

console.log(queryResult) // 95993.57
console.log(joinResult) // 95993.57000000001

Prisma information

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

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

model FirstModel {
  id           Int           @id @default(autoincrement())
  secondModels SecondModel[]
}

model SecondModel {
  id           Int        @id @default(autoincrement())
  value        Decimal
  firstModelId Int
  firstModel   FirstModel @relation(fields: [firstModelId], references: [id])

  @@index([firstModelId])
}
const joinResult = (await prisma.firstModel.findFirstOrThrow({
  relationLoadStrategy: 'join',
  include: { secondModels: true },
})).secondModels[0].value

Environment & setup

  • OS: Linux, Fedora 39
  • Database: MySQL
  • Node.js version: v20.11.0

Prisma Version

prisma                  : 5.10.2
@prisma/client          : 5.10.2
Computed binaryTarget   : rhel-openssl-3.0.x
Operating System        : linux
Architecture            : x64
Node.js                 : v20.11.0
Query Engine (Node-API) : libquery-engine 5a9203d0590c951969e85a7d07215503f4672eb9 (at node_modules/@prisma/engines/libquery_engine-rhel-openssl-3.0.x.so.node)
Schema Engine           : schema-engine-cli 5a9203d0590c951969e85a7d07215503f4672eb9 (at node_modules/@prisma/engines/schema-engine-rhel-openssl-3.0.x)
Schema Wasm             : @prisma/prisma-schema-wasm 5.10.0-34.5a9203d0590c951969e85a7d07215503f4672eb9
Default Engines Hash    : 5a9203d0590c951969e85a7d07215503f4672eb9
Studio                  : 0.499.0
Preview Features        : relationJoins
@michaelhays michaelhays added the kind/bug A reported bug. label Feb 21, 2024
@miguelff miguelff added tech/engines Issue for tech Engines. team/client Issue for team Client. 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 topic: joins labels Feb 23, 2024
@planklmar
Copy link

planklmar commented Mar 8, 2024

We found the same issue using Postgres, when using relationLoadStrategy: 'join'.
With load strategy relationLoadStrategy: 'query' or deactivating the preview Feature, the values are correct again.

In the query using "relationJoins", I can see a JSONB_BUILD_OBJECT maybe this is causing a wrong conversion to number at some point

Should I open another issue or can I leave this here?

prisma : 5.10.2
@prisma/client : 5.10.2
Postgres : 12
PreviewFeature: "relationJoins"

@Jolg42 Jolg42 added this to the 5.12.0 milestone Mar 14, 2024
@apolanc apolanc 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 Mar 14, 2024
@Weakky
Copy link
Member

Weakky commented Mar 22, 2024

Hey folks, this issue should be fixed in the next release of Prisma. Thanks for reporting 🙏

@michaelhays
Copy link
Author

Confirmed that this is fixed in 5.12.0! Thanks so much y'all :)

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/bug A reported bug. team/client Issue for team Client. tech/engines Issue for tech Engines. topic: floating point types Topic related to floating point types and precision loss topic: joins topic: relationJoins
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants