Skip to content

JSON value truncate floating numbers #3918

@Kerumen

Description

@Kerumen

Bug description

When I store a JSON value with floating numbers, Prisma seems to truncate the number and this leads to loss of precision and incorrect values.

How to reproduce

await prisma.user.create({
  data: {
    color: {
      r: 0.92156863212585449,
      g: 0.34117648005485535,
      b: 0.34117648005485535,
    },
  }
})

The logged query is (which makes me think this comes from Prisma and not from the database):

{
  timestamp: 2020-10-14T11:52:11.040Z,
  query: 'INSERT INTO "public"."User" ("id","color") VALUES ($1,$2) RETURNING "public"."User"."id"',
  params: '["ckg9c3vha0035qns5jyeyy8pb",{"r":0.9215686321258544,"g":0.34117648005485535,"b":0.34117648005485535}]',
  duration: 0,
  target: 'quaint::connector::metrics'
}

Notice the ending of the r number, it's truncated. But not for the b or g value.

Expected behavior

The stored value for r should be 0.92156863212585449 and not 0.9215686321258544.

Prisma information

model User {
  color Json
}

Environment & setup

  • OS: MacOS
  • Database: PostgreSQL
  • Node.js version: v12.16.2
  • Prisma version:
@prisma/cli          : 2.8.1
Current platform     : darwin
Query Engine         : query-engine 439da16b2f8314c6faca7d2dad2cdcf0732e8a9c (at node_modules/@prisma/cli/query-engine-darwin)
Migration Engine     : migration-engine-cli 439da16b2f8314c6faca7d2dad2cdcf0732e8a9c (at node_modules/@prisma/cli/migration-engine-darwin)
Introspection Engine : introspection-core 439da16b2f8314c6faca7d2dad2cdcf0732e8a9c (at node_modules/@prisma/cli/introspection-engine-darwin)
Format Binary        : prisma-fmt 439da16b2f8314c6faca7d2dad2cdcf0732e8a9c (at node_modules/@prisma/cli/prisma-fmt-darwin)
Studio               : 0.296.0

Related

This could be related
#3479
#2903

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions