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

Closed
opened 2026-04-13 10:30:22 -05:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/better-auth/better-auth/pull/8660

State: closed
Merged: Yes


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.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/8660 **State:** closed **Merged:** Yes --- ## 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. -->
GiteaMirror added the pull-request label 2026-04-13 10:30:22 -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#16372