prisma.update returns promise but doesn't do anything (most of the time)

As described in the title, prisma.update does not reliably trigger an update in the database. This is the gist of my code:
.middleware(...) //<-- works just fine
.onUploadComplete(({ file }) => {
console.log("on upload complete") // <-- works just fine
try {
const promise = prisma.plant.update({ // <-- returns a promise
where: { imageUrl: file.url },
data: {
imageStatus: "done",
},
});
console.log("update was called") // <-- works just fine
console.log(promise) // <-- works just fine
void promise
.then(() => console.log("update complete")) // <-- I only get here 1/3 times
.catch((err) => console.error("update failed")) // <-- I **sometimes** get here if I refresh the page before all updates are complete
}
catch (err) {
console.error(err) // <-- no errors are caught here
}
}
.middleware(...) //<-- works just fine
.onUploadComplete(({ file }) => {
console.log("on upload complete") // <-- works just fine
try {
const promise = prisma.plant.update({ // <-- returns a promise
where: { imageUrl: file.url },
data: {
imageStatus: "done",
},
});
console.log("update was called") // <-- works just fine
console.log(promise) // <-- works just fine
void promise
.then(() => console.log("update complete")) // <-- I only get here 1/3 times
.catch((err) => console.error("update failed")) // <-- I **sometimes** get here if I refresh the page before all updates are complete
}
catch (err) {
console.error(err) // <-- no errors are caught here
}
}
Additionally, I have enabled prisma query logs in production: ["query", "error", "warn"] Any ideas on what's going on? Please let me know if there's more information I should provide.
3 Replies
fszabo
fszaboOP2y ago
I've been doing research but still have not solved this. Prisma does lazy evaluation: https://github.com/prisma/docs/issues/800 But that still does not explain the behaviour. I have tried every possible way of triggering the evaluation. e.g:
await prisma.$transaction([
prisma.example.update({
where: { imageUrl: file.url },
data: {
imageStatus: "done",
},
}),
]);
await prisma.$transaction([
prisma.example.update({
where: { imageUrl: file.url },
data: {
imageStatus: "done",
},
}),
]);
e.g. without await or void (just in case that magically made a difference)
// eslint-disable-next-line @typescript-eslint/no-floating-promises
prisma.example
.update({
where: { imageUrl: file.url },
data: {
imageStatus: "done",
},
})
// eslint-disable-next-line @typescript-eslint/no-empty-function
.then(() => {});
// eslint-disable-next-line @typescript-eslint/no-floating-promises
prisma.example
.update({
where: { imageUrl: file.url },
data: {
imageStatus: "done",
},
})
// eslint-disable-next-line @typescript-eslint/no-empty-function
.then(() => {});
GitHub
Clarify when Prisma queries are run (PrismaPromise behavior) · Issu...
@Sytten brought up a good point in Slack that we don't really talk about when queries are executed. In this example: import { User } from '@prisma/client' export default async (app: App...
fszabo
fszaboOP2y ago
I can't make sense of this .. it really seems like it's just random
fszabo
fszaboOP2y ago
Just had one record update 5 hours after the call.
Want results from more Discord servers?
Add your server