[PR #7464] [CLOSED] fix(prisma-adapter): ignores ne null on nullable fields #7330

Closed
opened 2026-03-13 13:32:25 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7464
Author: @reslear
Created: 1/19/2026
Status: Closed

Base: mainHead: patch-15


📝 Commits (2)

  • 34d1dfb fix: enhance null condition handling in Prisma adapter
  • a79d865 fix: lint

📊 Changes

3 files changed (+8 additions, -3 deletions)

View changed files

📝 packages/better-auth/src/adapters/kysely-adapter/bun-sqlite-dialect.ts (+1 -1)
📝 packages/better-auth/src/adapters/kysely-adapter/node-sqlite-dialect.ts (+1 -1)
📝 packages/better-auth/src/adapters/prisma-adapter/prisma-adapter.ts (+6 -1)

📄 Description

Problem

The Prisma adapter ignores ne: null by returning {}.
For nullable fields (e.g. expiresAt), this effectively drops the filter.
As a result, the cleanup logic runs only with expiresAt < now and deletes API keys that have expiresAt: null.

Impact

Non-expiring API keys are unexpectedly deleted after calling /api-key/list when using Prisma + MongoDB.

Fix

If a field is nullable, map:

  • ne: null{ not: null }

Keep it as a no-op ({}) only for non-nullable fields.

Regression

PR https://github.com/better-auth/better-auth/pull/3413 reintroduces this issue.

The Prisma adapter again drops ne: null by returning {}, which removes the filter for nullable fields such as expiresAt. This causes the cleanup process to delete non-expiring API keys.

This appears to be an oversight in @okisdev’s change https://github.com/better-auth/better-auth/pull/5686.
@ping-maxwell, could you please take a look?


Summary by cubic

Fixes Prisma adapter handling of ne: null on nullable fields so filters are preserved and non-expiring API keys aren’t deleted during cleanup in Prisma + MongoDB.

  • Bug Fixes
    • Map ne: null to { not: null } when a field is nullable; keep it a no-op for non-nullable fields.
    • Use getFieldAttributes to detect nullability and apply the correct where condition for fields like expiresAt.

Written for commit a79d865330. 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/7464 **Author:** [@reslear](https://github.com/reslear) **Created:** 1/19/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `patch-15` --- ### 📝 Commits (2) - [`34d1dfb`](https://github.com/better-auth/better-auth/commit/34d1dfb4126ec23474fac06ee32640387c5d15da) fix: enhance null condition handling in Prisma adapter - [`a79d865`](https://github.com/better-auth/better-auth/commit/a79d865330315251a2af7bfec6c8fd38dd2fb2fa) fix: lint ### 📊 Changes **3 files changed** (+8 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/adapters/kysely-adapter/bun-sqlite-dialect.ts` (+1 -1) 📝 `packages/better-auth/src/adapters/kysely-adapter/node-sqlite-dialect.ts` (+1 -1) 📝 `packages/better-auth/src/adapters/prisma-adapter/prisma-adapter.ts` (+6 -1) </details> ### 📄 Description ## Problem The Prisma adapter ignores `ne: null` by returning `{}`. For nullable fields (e.g. `expiresAt`), this effectively **drops the filter**. As a result, the cleanup logic runs only with `expiresAt < now` and deletes API keys that have `expiresAt: null`. ## Impact Non-expiring API keys are unexpectedly deleted after calling `/api-key/list` when using **Prisma + MongoDB**. ## Fix If a field is **nullable**, map: - `ne: null` → `{ not: null }` Keep it as a no-op (`{}`) **only** for non-nullable fields. ## Regression PR https://github.com/better-auth/better-auth/pull/3413 reintroduces this issue. The Prisma adapter again drops `ne: null` by returning `{}`, which removes the filter for nullable fields such as `expiresAt`. This causes the cleanup process to delete non-expiring API keys. This appears to be an oversight in **@okisdev**’s change https://github.com/better-auth/better-auth/pull/5686. **@ping-maxwell**, could you please take a look? <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes Prisma adapter handling of ne: null on nullable fields so filters are preserved and non-expiring API keys aren’t deleted during cleanup in Prisma + MongoDB. - **Bug Fixes** - Map ne: null to { not: null } when a field is nullable; keep it a no-op for non-nullable fields. - Use getFieldAttributes to detect nullability and apply the correct where condition for fields like expiresAt. <sup>Written for commit a79d865330315251a2af7bfec6c8fd38dd2fb2fa. 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:32:25 -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#7330