Revert "fix(prisma-adapter): don't treat a null unique field as an update selector"

A null unique selector should keep failing instead of falling back to
updateMany, which can change several rows on providers that allow
multiple NULLs in a unique column.
This commit is contained in:
Gustavo Valverde
2026-10-15 11:43:49 +01:00
parent 77a7427cfe
commit 3edce1c2a0
2 changed files with 1 additions and 34 deletions
@@ -300,35 +300,6 @@ describe("prisma-adapter", () => {
);
});
it("falls back to updateMany for `eq null` on a unique field", async () => {
const update = vi.fn();
const updateMany = vi.fn().mockResolvedValue({ count: 1 });
const findFirst = vi.fn().mockResolvedValue({ id: "user-id" });
const adapter = prismaAdapter(
{ $transaction: vi.fn(), user: { findFirst, update, updateMany } },
{ provider: "mongodb" },
)({
user: {
additionalFields: {
username: { type: "string", unique: true, required: false },
},
},
});
await adapter.update({
model: "user",
where: [{ field: "username", operator: "eq", value: null }],
update: { name: "Updated" },
});
expect(update).not.toHaveBeenCalled();
expect(updateMany).toHaveBeenCalledWith(
expect.objectContaining({
where: { OR: [{ username: null }, { username: { isSet: false } }] },
}),
);
});
it("should use update (not updateMany) for insensitive mode on unsupported providers", async () => {
const update = vi.fn().mockResolvedValue({
id: "user-id",
@@ -219,11 +219,7 @@ export const prismaAdapter = (prisma: PrismaClient, config: PrismaConfig) => {
return false;
}
// A unique selector can't be null in Prisma's `WhereUniqueInput`.
if (
(condition.operator && condition.operator !== "eq") ||
condition.value === null
) {
if (condition.operator && condition.operator !== "eq") {
return false;
}