Prisma.DbNull doesn't work with Prisma Accelerate

Prisma Accelerate doesn't seem to support Prisma.DbNull. This is unexpected and production-breaking for us since we enabled Accelerate. For example, if you use Accelerate:
import { PrismaClient } from "@prisma/client/edge";
import { withAccelerate } from "@prisma/extension-accelerate";

export const db = new PrismaClient().$extends(withAccelerate());
import { PrismaClient } from "@prisma/client/edge";
import { withAccelerate } from "@prisma/extension-accelerate";

export const db = new PrismaClient().$extends(withAccelerate());
And have a model with an option JSON property:
model User {
id Int @default(autoincrement())
info Json?
}
model User {
id Int @default(autoincrement())
info Json?
}
If you try and update the value to Prisma.DbNull, that value becomes an empty object {} rather than NULL in the database and that's what the .update also responds with.
db.user.update({
where: { id: 1 },
data: { info: Prisma.DbNull }
}); // { id: 1, info: {} }
db.user.update({
where: { id: 1 },
data: { info: Prisma.DbNull }
}); // { id: 1, info: {} }
I can confirm that this is indeed an issue with Accelerate, because when I disable it, it works correctly.
2 Replies
AnandChowdhary
Prisma Accelerate doesn't seem to support Prisma.DbNull. This is unexpected and production-breaking for us since we enabled Accelerate. For example, if you use Accelerate:
import { PrismaClient } from "@prisma/client/edge";
import { withAccelerate } from "@prisma/extension-accelerate";

export const db = new PrismaClient().$extends(withAccelerate());
import { PrismaClient } from "@prisma/client/edge";
import { withAccelerate } from "@prisma/extension-accelerate";

export const db = new PrismaClient().$extends(withAccelerate());
And have a model with an optional JSON property:
model User {
id Int @default(autoincrement())
info Json?
}
model User {
id Int @default(autoincrement())
info Json?
}
If you try and update the value to Prisma.DbNull, that value becomes an empty object {} rather than NULL in the database and that's what the .update also responds with.
db.user.update({
where: { id: 1 },
data: { info: Prisma.DbNull }
}); // { id: 1, info: {} }
db.user.update({
where: { id: 1 },
data: { info: Prisma.DbNull }
}); // { id: 1, info: {} }
I can confirm that this is indeed an issue with Accelerate, because when I disable it, it works correctly.
Nurul
Nurul2w ago
Hey @AnandChowdhary Thanks for raising this. Is this happening on latest version of Prisma v5.20.0? To confirm, I understand the issue With Accelerate: If we update the value to Prisma.DbNull, that value becomes an empty object {} rather than NULL. Without Accelerate: The value gets updated to actual NULL value, which is expected and not the empty object. Correct? I just tried this with an sample project and got the correct value. i.e. Not an empty object
import { PrismaClient, Prisma } from "@prisma/client";
import { withAccelerate } from "@prisma/extension-accelerate";

let prismaAccelerate = new PrismaClient().$extends(withAccelerate());

async function main() {
await prismaAccelerate.userA.create({
data: {
id: 1,
},
});

const record = await prismaAccelerate.userA.update({
where: { id: 1 },
data: { info: Prisma.DbNull },
});

console.log(record);
}
import { PrismaClient, Prisma } from "@prisma/client";
import { withAccelerate } from "@prisma/extension-accelerate";

let prismaAccelerate = new PrismaClient().$extends(withAccelerate());

async function main() {
await prismaAccelerate.userA.create({
data: {
id: 1,
},
});

const record = await prismaAccelerate.userA.update({
where: { id: 1 },
data: { info: Prisma.DbNull },
});

console.log(record);
}
I got the expected output:
{ id: 1, info: null }
{ id: 1, info: null }
Want results from more Discord servers?
Add your server