P
Prisma4mo ago
acidjazz

Unique constraint fails when creating user(s)in parallel during tests for api endpoints

When I run tests in my app in parallel that have helpers that create users in the DB, i get this error:
FAIL ../test/cartridge.test.ts > /api/cartridge > post /api/cartridge - create a cartridge
PrismaClientKnownRequestError:
Invalid `prisma.user.upsert()` invocation:


Unique constraint failed on the constraint: `users_email_key`
❯ _n.handleRequestError ../node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:121:7749
❯ _n.handleAndLogRequestError ../node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:121:7057
❯ _n.request ../node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:121:6741
❯ l ../node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:130:9355
❯ Module.createUser utils/user.ts:11:10
9| let user: User | null = null
10|
11| user = await prisma.user.upsert({
| ^
12| where: { email: info.email },
13| create: {
❯ userFromEmail ../test/auth.ts:38:28
❯ Module.actingAs ../test/auth.ts:44:16
❯ ../test/cartridge.test.ts:12:28

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Serialized Error: { code: 'P2002', clientVersion: '5.18.0', meta: { modelName: 'User', target: 'users_email_key' }, batchRequestIdx: undefined }
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL ../test/cartridge.test.ts > /api/cartridge > post /api/cartridge - create a cartridge
PrismaClientKnownRequestError:
Invalid `prisma.user.upsert()` invocation:


Unique constraint failed on the constraint: `users_email_key`
❯ _n.handleRequestError ../node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:121:7749
❯ _n.handleAndLogRequestError ../node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:121:7057
❯ _n.request ../node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:121:6741
❯ l ../node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:130:9355
❯ Module.createUser utils/user.ts:11:10
9| let user: User | null = null
10|
11| user = await prisma.user.upsert({
| ^
12| where: { email: info.email },
13| create: {
❯ userFromEmail ../test/auth.ts:38:28
❯ Module.actingAs ../test/auth.ts:44:16
❯ ../test/cartridge.test.ts:12:28

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Serialized Error: { code: 'P2002', clientVersion: '5.18.0', meta: { modelName: 'User', target: 'users_email_key' }, batchRequestIdx: undefined }
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Although if i disable parallelism and only allow 1 thread this error never shows up.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server