[PR #8660] [MERGED] fix(adapters): use IS NULL / IS NOT NULL for null value comparisons #25026

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8660
Author: @olliethedev
Created: 3/17/2026
Status: Merged
Merged: 3/20/2026
Merged by: @himself65

Base: canaryHead: upstream/fix-adapter-null-eq-ne


📝 Commits (1)

  • b8f0f75 fix(adapters): use IS NULL / IS NOT NULL for null value comparisons in drizzle and kysely adapters

📊 Changes

3 files changed (+200 additions, -10 deletions)

View changed files

📝 packages/drizzle-adapter/src/drizzle-adapter.ts (+24 -6)
📝 packages/kysely-adapter/src/kysely-adapter.ts (+11 -4)
📝 packages/test-utils/src/adapter/suites/basic.ts (+165 -0)

📄 Description

Summary

In SQL, column = NULL and column != NULL always evaluate to UNKNOWN and return zero rows — IS NULL / IS NOT NULL are required for null comparisons. The drizzle-orm and kysely adapters were passing null directly to their equality helpers (eq, ne, eb(f, "=", ...), eb(f, "<>", ...)), silently producing zero rows for any where-clause with value: null.

Changes

  • packages/drizzle-adapter — add isNull / isNotNull guards for the eq and ne operators across all three convertWhereClause code paths (single-condition early-return, AND group, OR group)
  • packages/kysely-adapter — add IS NULL / IS NOT NULL guards for the eq and ne operators
  • packages/test-utils — add three regression tests to the shared normalTestSuite covering:
    1. single-condition { operator: "eq", value: null }IS NULL /{ operator: "ne", value: null }IS NOT NULL
    2. null condition inside an AND group
    3. null condition inside an OR group

Summary by cubic

Fixes null comparisons in drizzle-adapter and kysely-adapter. eq/ne with null now emit IS NULL/IS NOT NULL in queries and during update re-fetch, preventing zero-row results.

  • Bug Fixes
    • packages/drizzle-adapter: use isNull/isNotNull for eq/ne when value is null in single, AND, and OR groups.
    • packages/kysely-adapter: use IS/IS NOT for eq/ne with null, including the single-condition re-fetch path; use values[field] !== undefined to preserve falsy values like 0/false.
    • packages/test-utils: add regression tests for single, AND, and OR findMany cases with null, plus an update case verifying re-fetch with IS NULL.

Written for commit b8f0f75255. 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/8660 **Author:** [@olliethedev](https://github.com/olliethedev) **Created:** 3/17/2026 **Status:** ✅ Merged **Merged:** 3/20/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `upstream/fix-adapter-null-eq-ne` --- ### 📝 Commits (1) - [`b8f0f75`](https://github.com/better-auth/better-auth/commit/b8f0f75255d2f0f54f5eb4c059783a1dbb07ef15) fix(adapters): use IS NULL / IS NOT NULL for null value comparisons in drizzle and kysely adapters ### 📊 Changes **3 files changed** (+200 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `packages/drizzle-adapter/src/drizzle-adapter.ts` (+24 -6) 📝 `packages/kysely-adapter/src/kysely-adapter.ts` (+11 -4) 📝 `packages/test-utils/src/adapter/suites/basic.ts` (+165 -0) </details> ### 📄 Description ## Summary In SQL, `column = NULL` and `column != NULL` always evaluate to `UNKNOWN` and return zero rows — `IS NULL` / `IS NOT NULL` are required for null comparisons. The `drizzle-orm` and `kysely` adapters were passing `null` directly to their equality helpers (`eq`, `ne`, `eb(f, "=", ...)`, `eb(f, "<>", ...)`), silently producing zero rows for any where-clause with `value: null`. ## Changes - **`packages/drizzle-adapter`** — add `isNull` / `isNotNull` guards for the `eq` and `ne` operators across all three `convertWhereClause` code paths (single-condition early-return, AND group, OR group) - **`packages/kysely-adapter`** — add `IS NULL` / `IS NOT NULL` guards for the `eq` and `ne` operators - **`packages/test-utils`** — add three regression tests to the shared `normalTestSuite` covering: 1. single-condition `{ operator: "eq", value: null }` → `IS NULL` /`{ operator: "ne", value: null }` → `IS NOT NULL` 2. null condition inside an AND group 3. null condition inside an OR group <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes null comparisons in `drizzle-adapter` and `kysely-adapter`. `eq`/`ne` with `null` now emit `IS NULL`/`IS NOT NULL` in queries and during update re-fetch, preventing zero-row results. - **Bug Fixes** - `packages/drizzle-adapter`: use `isNull`/`isNotNull` for `eq`/`ne` when value is `null` in single, AND, and OR groups. - `packages/kysely-adapter`: use `IS`/`IS NOT` for `eq`/`ne` with `null`, including the single-condition re-fetch path; use `values[field] !== undefined` to preserve falsy values like `0`/`false`. - `packages/test-utils`: add regression tests for single, AND, and OR `findMany` cases with `null`, plus an `update` case verifying re-fetch with `IS NULL`. <sup>Written for commit b8f0f75255d2f0f54f5eb4c059783a1dbb07ef15. 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-04-15 22:41:45 -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#25026