[PR #7096] [MERGED] fix(prisma-adapter): lift eq AND conditions to root so update detects unique where field #7072

Closed
opened 2026-03-13 13:23:07 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7096
Author: @ping-maxwell
Created: 1/2/2026
Status: Merged
Merged: 1/2/2026
Merged by: @Bekacru

Base: canaryHead: fix/primsa-update-unique-AND-issue


📝 Commits (3)

  • 149ebfb fix(prisma-adapter): update operations fail with non-unique fields
  • 14b4ca3 chore: remove logs
  • 41af0c9 Merge branch 'canary' into fix/primsa-update-unique-AND-issue

📊 Changes

2 files changed (+57 additions, -0 deletions)

View changed files

📝 packages/better-auth/src/adapters/prisma-adapter/prisma-adapter.ts (+39 -0)
📝 packages/better-auth/src/adapters/tests/basic.ts (+18 -0)

📄 Description

closes https://github.com/better-auth/better-auth/issues/5929

There are cases where we call adapter.update and even if we provide a unique field it will still fail saying we didn't.
This happens because if the where clause of the update included two where conditions making it an AND operation then Prisma will not detect that unique field within the AND array as it requires all unique field to be defined at the root level of the where clause object.

This PR simply extracts the AND clause that uses eq operations to be at the root level of the where obj under update actions.


Summary by cubic

Fixes Prisma adapter update failures when a unique field is nested under AND. Simple equality filters are lifted to the root of the where clause so Prisma recognizes the unique field.

  • Bug Fixes
    • For update actions, extract AND conditions with eq into the root where object.
    • Leave complex operators under AND; keep OR conditions unchanged.
    • Added a test to verify updates succeed with email + id combined under AND.

Written for commit 41af0c95f8. Summary will update on new commits.


🔄 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/7096 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 1/2/2026 **Status:** ✅ Merged **Merged:** 1/2/2026 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/primsa-update-unique-AND-issue` --- ### 📝 Commits (3) - [`149ebfb`](https://github.com/better-auth/better-auth/commit/149ebfb1bab732e72a042ca9f3edf7cff78b0313) fix(prisma-adapter): `update` operations fail with non-unique fields - [`14b4ca3`](https://github.com/better-auth/better-auth/commit/14b4ca3ed21cfc3da90bbae38e362ab90c410471) chore: remove logs - [`41af0c9`](https://github.com/better-auth/better-auth/commit/41af0c95f879cc7f21a1b25f6c652c25794a8698) Merge branch 'canary' into fix/primsa-update-unique-AND-issue ### 📊 Changes **2 files changed** (+57 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/adapters/prisma-adapter/prisma-adapter.ts` (+39 -0) 📝 `packages/better-auth/src/adapters/tests/basic.ts` (+18 -0) </details> ### 📄 Description closes https://github.com/better-auth/better-auth/issues/5929 There are cases where we call `adapter.update` and even if we provide a unique field it will still fail saying we didn't. This happens because if the where clause of the update included two where conditions making it an `AND` operation then Prisma will not detect that unique field within the `AND` array as it requires all unique field to be defined at the root level of the where clause object. This PR simply extracts the AND clause that uses `eq` operations to be at the root level of the where obj under `update` actions. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes Prisma adapter update failures when a unique field is nested under AND. Simple equality filters are lifted to the root of the where clause so Prisma recognizes the unique field. - **Bug Fixes** - For update actions, extract AND conditions with eq into the root where object. - Leave complex operators under AND; keep OR conditions unchanged. - Added a test to verify updates succeed with email + id combined under AND. <sup>Written for commit 41af0c95f879cc7f21a1b25f6c652c25794a8698. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <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-03-13 13:23:07 -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#7072