Open moshOntong-IT opened 2 hours ago
Hii @moshOntong-IT,
Could you please share the query that triggered this error? Thank you!
I'm getting the same error when I use autocaching on the findMany method. I've noticed my model returns undefined instead of null on a cache miss and have had to implement a retry method into my model to get around this at the moment:
export async function getAssessmentsForUser(
userId: number,
maxRetries = 3
): Promise<AssessmentWithScenario[]> {
const customKey = prisma.getAutoKey({
args: { where: { userId: userId } },
model: "Assessment",
operation: "findMany",
});
let retries = 0;
while (retries < maxRetries) {
try {
let assessments: AssessmentWithScenario[] =
await prisma.assessment.findMany({
where: { userId: userId },
orderBy: { id: "asc" },
cache: { ttl: 5, key: customKey },
});
assessments = await Promise.all(
assessments.map(async (assessment) => {
assessment.scenario = await getScenarioByKey(
assessment.scenarioKey || ""
);
return assessment;
})
);
return assessments;
} catch (error) {
retries++;
}
}
throw new Error("Failed to fetch assessments after multiple retries");
}
Code: