prisma: Error `Could not convert argument value Object to ArgumentValue` when writing bigint value
Bug description
await prisma.stakeRecord.create(
Could not convert argument value Object {"$type": String("BigInt"), "value": String("47359100000000000000")} to ArgumentValue.
at zr.handleRequestError (/Users/suhao/github/project/node_modules/.pnpm/@prisma+client@5.0.0_prisma@5.0.0/node_modules/@prisma/client/runtime/library.js:122:8480)
at zr.handleAndLogRequestError (/Users/suhao/github/project/node_modules/.pnpm/@prisma+client@5.0.0_prisma@5.0.0/node_modules/@prisma/client/runtime/library.js:122:7697)
at zr.request (/Users/suhao/github/project/node_modules/.pnpm/@prisma+client@5.0.0_prisma@5.0.0/node_modules/@prisma/client/runtime/library.js:122:7307)
at async fetchEvents (/Users/suhao/github/project/daemon/listenBlock.ts:45:3)
at async /Users/suhao/github/project/daemon/listenBlock.ts:58:5 {
clientVersion: '5.0.0'
}
How to reproduce
Expected behavior
Save correctly
Prisma information
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
// NOTE: When using mysql or sqlserver, uncomment the @db.Text annotations in model Account below
// Further reading:
// https://next-auth.js.org/adapters/prisma#create-the-prisma-schema
// https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#string
url = env("DATABASE_URL")
}
model StakeRecord {
id String @id @default(cuid())
user String
amountU BigInt @db.BigInt
amountT BigInt @db.BigInt
blockHash String
blockNumber Int
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
}
await prisma.stakeRecord.create({
data: {
user: '',
amountT: BigInt(47359100000000000000),
amountU: BigInt(1),
blockHash: '',
blockNumber: 1,
}
})
Environment & setup
- OS: macos
- Database: PostgreSQL
- Node.js version: v18.13.0
Prisma Version
5.0.0
About this issue
- Original URL
- State: open
- Created 10 months ago
- Reactions: 2
- Comments: 16 (3 by maintainers)
Error is caused by difference between javascript’s BigInt Max size and Databases’ bigint type’s max size.
e.g. 1n~1000n, BigInt(1000) is ok to insert. But BigInt(47359100000000000000) is bigger than 2^64 -1 which is mysql bigint type and emits errors.
https://dev.mysql.com/doc/refman/8.0/en/integer-types.html
Also, Postgres uses int8 on bigint like mysql 😦
I think it is already existing issue. Same thoughts
https://github.com/prisma/prisma/issues/19860