-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Bug: FindXOrThrow don't get batched on the engine #16625
Comments
Any plans for this to be fixed? |
Was told to copy/paste this same info over here, even though it's obviously available in the link to the now-closed issue above. Maybe this will cast a spell to get a Prisma response from this 6 month old bug: Bug descriptionOver in MichalLytek/typegraphql-prisma#383 we've been able to repro an issue where it looks like How to reproduceEasiest way would be to follow the repro steps in the typegraphql-prisma issue, this issue also has valid repro steps: #18838 Expected behaviorWould expect Prisma informationSeeing this with Prisma 4.13.0, but possibly earlier as well. Environment & setup
Prisma VersionPrisma 4.13.0. |
@janpio this is very big issue, at least for those using GraphQL. It is very common to have a lot of entities and each of them have properties which are IDs in the DB and loading by ID in the resolver. Since the ID exists, As an example, if there's a query that returns 20 |
If someone is interested, this can possibly be patched temporarily with a middleware like this, very risky of course import { Prisma } from '@prisma/client'
const middleware: Prisma.Middleware = async (params, next) => {
const needsPatch = (params.action as string) === 'findUniqueOrThrow'
if (needsPatch) {
params.action = 'findUnique'
}
const ret = await next(params)
if (needsPatch && !ret) {
const model = params.model || ''
const table = model[0].toLowerCase() + model.slice(1)
throw new Err(`Invalid \`prisma.${table}.findUniqueOrThrow()\` invocation: An operation failed because it depends on one or more records that were required but not found. Expected a record, found none.)`)
}
return ret
}
class Err extends Error {
public code = 'P2025'
constructor (message: string) {
super(message)
}
}
export default middleware |
This is fixed in prisma/prisma-engines#4019 and #19554 and will be available in next Prisma release. |
@SevInf I read the release email for 4.16.0, I don't see this issue in the list. Is this included? |
@flesler, yes, this is a part of 4.16.0 |
Thanks for the note @flesler, I applied the milestone and added the issue to the release notes 👍 |
I am seeing the following issue with batching:
prisma.user.findUnique({ where { id } });
-> batching occursprisma.user.findUnique({ where { id } }).posts();
-> batching occursprisma.user.findUniqueOrThrow({ where { id } });
-> batching does NOT occurprisma.user.findUniqueOrThrow({ where { id } }).posts();
-> batching does NOT occurexample based on Query optimization page
Originally posted by @nowlena in prisma/prisma-engines#3458 (comment)
The text was updated successfully, but these errors were encountered: