Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: client handling of batched queries when some fail, and some not (#…
…16574) * Fix some error management in engine code * Bump versions * Added regression test * Allow for data proxy tests to run * Run in every provider * Temporary skip data proxy * Make tests resilient to mongo id format * Try to unskip the test * Reproduce & fix batch query issue for data proxy Co-authored-by: Sergey Tatarintsev <tatarintsev@prisma.io>
- Loading branch information
Showing
8 changed files
with
136 additions
and
30 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
packages/client/tests/functional/find-unique-or-throw-batching/_matrix.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { defineMatrix } from '../_utils/defineMatrix' | ||
import { allProviders } from '../_utils/providers' | ||
|
||
export default defineMatrix(() => [allProviders]) |
19 changes: 19 additions & 0 deletions
19
packages/client/tests/functional/find-unique-or-throw-batching/prisma/_schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { idForProvider } from '../../_utils/idForProvider' | ||
import testMatrix from '../_matrix' | ||
|
||
export default testMatrix.setupSchema(({ provider }) => { | ||
return /* Prisma */ ` | ||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
datasource db { | ||
provider = "${provider}" | ||
url = env("DATABASE_URI_${provider}") | ||
} | ||
model User { | ||
id ${idForProvider(provider)} | ||
} | ||
` | ||
}) |
46 changes: 46 additions & 0 deletions
46
packages/client/tests/functional/find-unique-or-throw-batching/tests.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { faker } from '@faker-js/faker' | ||
|
||
import testMatrix from './_matrix' | ||
// @ts-ignore | ||
import type { PrismaClient } from './node_modules/@prisma/client' | ||
|
||
declare let prisma: PrismaClient | ||
const missing = faker.database.mongodbObjectId() | ||
|
||
testMatrix.setupTestSuite((suiteConfig, suiteMeta, clientMeta) => { | ||
let id1: string | ||
let id2: string | ||
beforeAll(async () => { | ||
id1 = await prisma.user | ||
.create({ | ||
data: {}, | ||
}) | ||
.then((user) => user.id) | ||
|
||
id2 = await prisma.user | ||
.create({ | ||
data: {}, | ||
}) | ||
.then((user) => user.id) | ||
}) | ||
|
||
test('batched errors are when all objects in batch are found', async () => { | ||
const found = prisma.user.findUniqueOrThrow({ where: { id: id1 } }) | ||
const foundToo = prisma.user.findUniqueOrThrow({ where: { id: id2 } }) | ||
const result = await Promise.allSettled([found, foundToo]) | ||
expect(result).toEqual([ | ||
{ status: 'fulfilled', value: { id: id1 } }, | ||
{ status: 'fulfilled', value: { id: id2 } }, | ||
]) | ||
}) | ||
|
||
test('batched errors when some of the objects not found', async () => { | ||
const found = prisma.user.findUniqueOrThrow({ where: { id: id1 } }) | ||
const notFound = prisma.user.findUniqueOrThrow({ where: { id: missing } }) | ||
const newResult = await Promise.allSettled([found, notFound]) | ||
expect(newResult).toEqual([ | ||
{ status: 'fulfilled', value: { id: id1 } }, | ||
{ status: 'rejected', reason: expect.objectContaining({ code: 'P2025' }) }, | ||
]) | ||
}) | ||
}, {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters