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

PANIC in libs/prisma-models/src/record.rs:161:30Invalid coercion encountered: ConversionFailure("Float(BigDecimal(\"519.05\"))", "Decimal") #7061

Closed
jonnyleeharris opened this issue May 12, 2021 · 6 comments · Fixed by prisma/prisma-engines#2988
Assignees
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/engines/query engine Issue in the Query Engine topic: basic error report topic: Decimal Scalar type `Decimal` topic: floating point types Topic related to floating point types and precision loss
Milestone

Comments

@jonnyleeharris
Copy link

Hi Prisma Team! My Prisma Client just crashed. This is the report:

Versions

Name Version
Node v14.3.0
OS darwin
Prisma Client 2.22.1
Query Engine query-engine 60cc71d884972ab4e897f0277c4b84383dddaf6c
Database undefined

Query

{"X":false}

Logs

:engine {
  prisma:engine   error: Error: connect ECONNREFUSED 127.0.0.1:58287
  prisma:engine       at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
  prisma:engine     errno: -61,
  prisma:engine     code: 'ECONNREFUSED',
  prisma:engine     syscall: 'connect',
  prisma:engine     address: '127.0.0.1',
  prisma:engine     port: 58287
  prisma:engine   }
  prisma:engine }  
  prisma:engine {
  prisma:engine   cwd: '/prisma'
  prisma:engine }  
  prisma:engine Search for Query Engine in /node_modules/.prisma/client  
  plusX Execution permissions of /node_modules/.prisma/client/query-engine-darwin are fine  +2s
  prisma:engine { flags: [ '--enable-raw-queries', '--port', '58295' ] }  
  prisma:engine stdout  Starting a postgresql pool with 17 connections.  
  prisma:engine stdout  Fetched a connection from the pool  +1s
  prisma:engine stdout  Started http server on http://127.0.0.1:58295  
  prisma:engine Search for Query Engine in /node_modules/.prisma/client  
  plusX Execution permissions of /node_modules/.prisma/client/query-engine-darwin are fine  +1s
  prisma:engine Client Version: 2.22.1  
  prisma:engine Engine Version: query-engine 60cc71d884972ab4e897f0277c4b84383dddaf6c  
  prisma:engine Active provider: postgresql  
  prisma:engine stdout  Fetched a connection from the pool  
  prisma:engine stdout  Unknown error  
  prisma:engine stdout  Unknown error  
  prisma:engine stdout  Unknown error  
  prisma:engine stdout  Unknown error  
  prisma:engine stdout  Unknown error  
  prisma:engine stdout  Unknown error  
  prisma:engine stdout  PANIC in libs/prisma-models/src/record.rs:161:30
Invalid coercion encountered: ConversionFailure("Float(BigDecimal(\"519.05\"))", "Decimal")  
  prisma:engine {
  prisma:engine   error: SocketError: other side closed
  prisma:engine       at Socket.onSocketEnd (
/node_modules/@prisma/client/runtime/index.js:25530:24)
  prisma:engine       at Socket.emit (events.js:327:22)
  prisma:engine       at Socket.EventEmitter.emit (domain.js:485:12)
  prisma:engine       at endReadableNT (_stream_readable.js:1224:12)
  prisma:engine       at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  prisma:engine     code: 'UND_ERR_SOCKET'
  prisma:engine   }
  prisma:engine }  

Client Snippet

let spec = await prisma.line_item_specification_revisions.findUnique({
				where: {
					line_item_revision_id: parseFloat(parent.id)
				},
				include: {
					line_item_specification: {
						select: {
							line_item_edge_rails: true,							
							line_item_mid_rails: true							
						}
					}
				}
			})

Schema

model line_item_specification_revisions {
  line_item_revision_id      BigInt                    @unique
  line_item_specification_id BigInt
  order_line_item_revisions  order_line_item_revisions @relation(fields: [line_item_revision_id], references: [order_line_item_revision_id])
  line_item_specification    line_item_specification   @relation(fields: [line_item_specification_id], references: [line_item_specification_id])

  @@id([line_item_revision_id, line_item_specification_id])
}

model line_item_specification {
  line_item_edge_rails              line_item_edge_rails[]
  line_item_mid_rails               line_item_mid_rails[]
  line_item_specification_revisions line_item_specification_revisions[]
}

model line_item_edge_rails {
  line_item_specification_id BigInt
  tier_index                 Int                     @default(0)
  edge                       String
  height                     Decimal                 @db.Decimal
  is_critical                Boolean?
  line_item_specification    line_item_specification @relation(fields: [line_item_specification_id], references: [line_item_specification_id])

  @@unique([line_item_specification_id, tier_index, edge], name: "line_item_edge_rails_line_item_specification_id_tier_index__key")
}

model line_item_mid_rails {
  line_item_specification_id BigInt
  height                     Decimal                 @db.Decimal
  position                   Decimal                 @db.Decimal
  is_critical                Boolean?
  line_item_specification    line_item_specification @relation(fields: [line_item_specification_id], references: [line_item_specification_id])

  @@unique([line_item_specification_id, position], name: "line_item_mid_rails_line_item_specification_id_position_key")
}


@jonnyleeharris
Copy link
Author

jonnyleeharris commented May 13, 2021

If I remove the position column from unique constraint and add a primary key to line_item_mid_rails table the panic no longer occurs:

model line_item_mid_rails {
  line_item_specification_id BigInt
  height                     Decimal                 @db.Decimal
  position                   Decimal                 @db.Decimal
  is_critical                Boolean?
  line_item_mid_rails_id     BigInt                  @id @default(autoincrement())
  line_item_specification    line_item_specification @relation(fields: [line_item_specification_id], references: [line_item_specification_id])
}

@pantharshit00
Copy link
Contributor

Hey @jonnyleeharris

Can you please try the dev version once? npm install prisma@dev @prisma/client@dev? I remember we changed this conversion very recently.

@pantharshit00 pantharshit00 added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. topic: basic error report team/client Issue for team Client. labels May 17, 2021
@zackify
Copy link

zackify commented Oct 21, 2021

I'm seeing this same issue when using an id and decimal field together

  county_key       Decimal                  @id(map: "mp_census_county_0") @db.Decimal(28, 6)

thread 'tokio-runtime-worker' panicked at 'Invalid coercion encountered: ConversionFailure("Float(BigDecimal("122"))", "Decimal")', query-engine/prisma-models/src/record.rs:161:30

it only seems to happen when the id is also on the field for me

@janpio
Copy link
Member

janpio commented Nov 4, 2021

Thanks @zackify for the additional information. Is it enough to have a table with such a field, some data in it and then read the data or how can we trigger the error? If we can reproduce this, we can most probably fix it as well.

@janpio janpio added the topic: floating point types Topic related to floating point types and precision loss label Nov 4, 2021
@haydenbriese
Copy link

haydenbriese commented Apr 10, 2022

Example

DB: PostgreSQL

Schema excerpt

model Example {
  number   Decimal   @id
}

Example call

await prisma.example.create({
  data: { 
      number: '1' + '0'.repeat(9),
   },
});

Workaround

Use string for the id.
If you need to perform number-specific operations on the data then create a duplicate field i.e.

model Example {
  number    String   @id
  number2  Decimal
}

However if the number is large enough this workaround may run into Large decimals cause panick #12761

@Weakky
Copy link
Member

Weakky commented Jun 17, 2022

Hey,

This was fixed by prisma/prisma-engines#2988 and should be available in the next release.

Closing now, thanks for reporting 🙏

@Weakky Weakky closed this as completed Jun 17, 2022
@janpio janpio added this to the 4.0.x milestone Jun 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/engines/query engine Issue in the Query Engine topic: basic error report topic: Decimal Scalar type `Decimal` topic: floating point types Topic related to floating point types and precision loss
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants