Skip to content

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

Merged
Bekacru merged 3 commits intobetter-auth:canaryfrom
ping-maxwell:fix/primsa-update-unique-AND-issue
Jan 2, 2026
Merged

fix(prisma-adapter): lift eq AND conditions to root so update detects unique where field#7096
Bekacru merged 3 commits intobetter-auth:canaryfrom
ping-maxwell:fix/primsa-update-unique-AND-issue

Conversation

@ping-maxwell
Copy link
Copy Markdown
Member

@ping-maxwell ping-maxwell commented Jan 2, 2026

closes #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 41af0c9. Summary will update on new commits.

@vercel
Copy link
Copy Markdown

vercel bot commented Jan 2, 2026

@ping-maxwell is attempting to deploy a commit to the better-auth Team on Vercel.

A member of the Team first needs to authorize it.

@ping-maxwell ping-maxwell changed the title fix(prisma-adapter): update operations fail with non-unique fields fix(prisma-adapter): update fails with non-unique AND where clauses Jan 2, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="packages/better-auth/src/adapters/prisma-adapter/prisma-adapter.ts">

<violation number="1" location="packages/better-auth/src/adapters/prisma-adapter/prisma-adapter.ts:466">
P2: Debug `console.log` statement should be removed before merging. This will log internal query details to the console on every update operation in production.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Jan 2, 2026

Open in StackBlitz

better-auth

npm i https://pkg.pr.new/better-auth/better-auth@7096

@better-auth/cli

npm i https://pkg.pr.new/better-auth/better-auth/@better-auth/cli@7096

@better-auth/core

npm i https://pkg.pr.new/better-auth/better-auth/@better-auth/core@7096

@better-auth/expo

npm i https://pkg.pr.new/better-auth/better-auth/@better-auth/expo@7096

@better-auth/oauth-provider

npm i https://pkg.pr.new/better-auth/better-auth/@better-auth/oauth-provider@7096

@better-auth/passkey

npm i https://pkg.pr.new/better-auth/better-auth/@better-auth/passkey@7096

@better-auth/scim

npm i https://pkg.pr.new/better-auth/better-auth/@better-auth/scim@7096

@better-auth/sso

npm i https://pkg.pr.new/better-auth/better-auth/@better-auth/sso@7096

@better-auth/stripe

npm i https://pkg.pr.new/better-auth/better-auth/@better-auth/stripe@7096

@better-auth/telemetry

npm i https://pkg.pr.new/better-auth/better-auth/@better-auth/telemetry@7096

commit: 41af0c9

@ping-maxwell ping-maxwell changed the title fix(prisma-adapter): update fails with non-unique AND where clauses fix(prisma-adapter): lift eq AND conditions to root so update detects unique where field Jan 2, 2026
@Bekacru Bekacru merged commit 6128493 into better-auth:canary Jan 2, 2026
8 of 10 checks passed
himself65 pushed a commit that referenced this pull request Jan 10, 2026
himself65 pushed a commit that referenced this pull request Jan 10, 2026
himself65 pushed a commit that referenced this pull request Jan 10, 2026
himself65 pushed a commit that referenced this pull request Jan 10, 2026
himself65 pushed a commit that referenced this pull request Jan 10, 2026
himself65 pushed a commit that referenced this pull request Jan 12, 2026
himself65 pushed a commit that referenced this pull request Jan 12, 2026
@better-auth better-auth locked as resolved and limited conversation to collaborators Apr 1, 2026
@bytaesu bytaesu added the locked Locked conversations after being closed for 7 days label Apr 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked Locked conversations after being closed for 7 days

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prisma adapter uses db[model].update with non‑unique where (AND …) → PrismaClientValidationError

3 participants