PrismaClientUnknownRequestError in prisma.user.create(...) with trigger
See original GitHub issueBug description
When I try to create a new user I got this error:
prisma:info Starting a mysql pool with 9 connections.
prisma:query BEGIN
prisma:query INSERT INTO `iosef_db`.`user` (`id`,`hash`,`salt`,`password`,`email`,`token`,`tokenExpiration`) VALUES (?,?,?,?,?,?,?)
prisma:query SELECT `iosef_db`.`user`.`id`, `iosef_db`.`user`.`hash`, `iosef_db`.`user`.`salt`, `iosef_db`.`user`.`password`, `iosef_db`.`user`.`email`, `iosef_db`.`user`.`token`, `iosef_db`.`user`.`tokenExpiration` FROM `iosef_db`.`user` WHERE `iosef_db`.`user`.`id` = ? LIMIT ? OFFSET ?
prisma:query ROLLBACK
PrismaClientUnknownRequestError:
Invalid `prisma.user.create()` invocation in
/api/src/prisma/models/User.model.ts:150:44
147 const salt = await bcrypt.genSalt(10);
148 const hashedPassword = await bcrypt.hash(data.password, salt);
149
→ 150 const user = await prisma.user.create(
Query createOneuser is required to return data, but found no record(s).
at cb (/api/node_modules/@prisma/client/runtime/index.js:38679:17)
at async Function.create (/api/src/prisma/models/User.model.ts:150:26)
at async loginController.test (/api/src/controllers/login.controller.ts:31:25)
at async /api/node_modules/@nestjs/core/router/router-execution-context.js:46:28
at async /api/node_modules/@nestjs/core/router/router-proxy.js:9:17 {
clientVersion: '3.5.0'
}
How to reproduce
await prisma.user.create({
data: {
email: 'someone@gmail.com',
password: 'password',
tokenExpiration: `1643896265257`,
token: 'eyJhbGciOiJIUz…Nn0.ouT9RiI6X0vXEkjf9rxfUhIu_UUYZ-ZkRUCuqW-9tUk',
salt: '$2b$10$q.y4.vrHKxDYMQkeWm9xW.',
hash: '$2b$10$Qju63Il/erAV1epJyeEk6epdX5/zD.6kC4oTTjTtlHeUpCUDfpHay'
}
});
Expected behavior
It should create the user without error
Prisma information
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("MYSQL_URL")
}
model user {
id String @id @default("") @db.VarChar(36)
hash String @db.VarChar(80)
salt String @db.VarChar(80)
password String @db.VarChar(22)
email String @db.VarChar(50)
token String @db.VarChar(280)
tokenExpiration String @db.VarChar(50)
}
Environment & setup
- OS: Linux (Inside a docker container
node:16.13.0
) - Database: MySQL
- Node.js version: 16.13.0
Prisma Version
3.5.0
Edit
I tried using prisma.user.createMany(...);
and it works perfectly!
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:14 (7 by maintainers)
Top Results From Across the Web
Error message reference - Prisma
Prisma Client throws a PrismaClientUnknownRequestError exception if the query engine returns an error related to a request that does not have an error...
Read more >Intermittent prisma crashes - RedwoodJS Community
api | error creating user PrismaClientInitializationError: api ... Looking at the logs, out of 303 invocations I triggered the error twice.
Read more >https://cdn.jsdelivr.net/npm/prisma@3.5.0/prisma-c...
Sql, ...values: any[]): any; __internal_triggerPanic(fatal: boolean): any; ... this same config is passed to {@link getPrismaClient} which creates a ...
Read more >@prisma/cli: Versions | Openbase
NewFromFloat(1.23456789) created, err := client.User.CreateOne( db.User. ... generation is always triggered to avoid issues where the Prisma Client API is ...
Read more >Highlights - FeedsAnywhere
Prisma will use the native database upsert if: There are no nested queries in the upsert 's create and update options; The query...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok, now I can reproduce this with 4.3.1.
What happens here is that we generate that empty string default value in the core, and we expect to find this new record with that value. The database generates a UUID, and our
SELECT
does not find anything.It is unclear can you even do this with MySQL and an ORM. MySQL does not have
RETURNING
for anINSERT
, so we have no idea what is the generated UUID value for the record.Easy reproduction with the migration:
Probably related: https://github.com/prisma/prisma/issues/14918