[PR #8524] [MERGED] fix(prisma-adapter): fall back to updateMany for non-unique updates #24937

Closed
opened 2026-04-15 22:38:34 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8524
Author: @himself65
Created: 3/9/2026
Status: Merged
Merged: 3/9/2026
Merged by: @himself65

Base: canaryHead: worktree-fix-prisma-update-8365


📝 Commits (1)

  • f790eb6 fix(prisma-adapter): fall back to updateMany for non-unique updates

📊 Changes

2 files changed (+152 additions, -2 deletions)

View changed files

📝 packages/prisma-adapter/src/prisma-adapter.test.ts (+101 -2)
📝 packages/prisma-adapter/src/prisma-adapter.ts (+51 -0)

📄 Description

Summary

  • Prisma's update() requires a WhereUniqueInput, so updating by non-unique fields like verification.identifier causes a PrismaClientValidationError
  • Detect whether the where clause contains a root-level unique field (id or a field marked unique in the schema)
  • When no unique field is present, use updateMany + findFirst instead of update
  • Keep the existing update path for unique fields like id and unique session tokens

Closes #8365

Test plan

  • Add regression test for non-unique verification identifier updates
  • Add test to ensure unique non-id fields (e.g. session token) still use update
  • Verify existing prisma adapter test still passes
  • pnpm biome check passes on changed files

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/8524 **Author:** [@himself65](https://github.com/himself65) **Created:** 3/9/2026 **Status:** ✅ Merged **Merged:** 3/9/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `worktree-fix-prisma-update-8365` --- ### 📝 Commits (1) - [`f790eb6`](https://github.com/better-auth/better-auth/commit/f790eb68827b9ec181d6d1f1f8d98cb828b542bc) fix(prisma-adapter): fall back to updateMany for non-unique updates ### 📊 Changes **2 files changed** (+152 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/prisma-adapter/src/prisma-adapter.test.ts` (+101 -2) 📝 `packages/prisma-adapter/src/prisma-adapter.ts` (+51 -0) </details> ### 📄 Description ## Summary - Prisma's `update()` requires a `WhereUniqueInput`, so updating by non-unique fields like `verification.identifier` causes a `PrismaClientValidationError` - Detect whether the `where` clause contains a root-level unique field (`id` or a field marked `unique` in the schema) - When no unique field is present, use `updateMany` + `findFirst` instead of `update` - Keep the existing `update` path for unique fields like `id` and unique session tokens Closes #8365 ## Test plan - [x] Add regression test for non-unique verification identifier updates - [x] Add test to ensure unique non-id fields (e.g. session token) still use `update` - [x] Verify existing prisma adapter test still passes - [x] `pnpm biome check` passes on changed files --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-15 22:38:34 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#24937