SWE-Rebench v2 hard task
harbor run -t ibragim-badertdinov/better-auth__better-auth-9756harbor download ibragim-badertdinov/better-auth__better-auth-9756[Bug] Drizzle adapter drops OR clauses when mixed with AND connectors in where conditions
The Drizzle adapter has a bug where queries with mixed AND/OR connectors in where clauses will drop one of the connector groups, leading to incorrect query results.
When using findMany or findOne with a where clause that contains both AND and OR connectors, only the first connector group is applied. The second group is silently ignored.
Both AND and OR connector groups should be combined properly, resulting in queries like:
sql
WHERE (condition1 AND condition2) AND (condition3 OR condition4)
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
// Create users with different attributes
await adapter.create({
model: "user", import { drizzleAdapter } from 'better-auth/adapters/drizzle';
// Create users with different attributes
await adapter.create({
model: "user",
data: { email: "admin@company.com", name: "Admin User" }
});
await adapter.create({
model: "user",
data: { email: "other@company.com", name: "Other Person" }
});
// Query with mixed connectors
const result = await adapter.findMany({
model: "user",
where: [
{ field: "email", value: "company.com", operator: "contains" }, // implicit AND
{ field: "name", value: "Admin", operator: "contains", connector: "OR" },
],
});
// Expected: 2 users (both @company.com users match)
// Actual: 1 user (only the AND condition is applied, OR is dropped)
data: { email: "admin@company.com", name: "Admin User" }
});
await adapter.create({
model: "user",
data: { email: "other@company.com", name: "Other Person" }
});
// Query with mixed connectors
const result = await adapter.findMany({
model: "user",
where: [
{ field: "email", value: "company.com", operator: "contains" }, // implicit AND
{ field: "name", value: "Admin", operator: "contains", connector: "OR" },
],
});
// Expected: 2 users (both @company.com users match)
// Actual: 1 user (only the AND condition is applied, OR is dropped)
Root Cause In ,drizzle-adapter.ts, the convertWhereClause function builds both andClause and orClause but return them as array [andClause, orClause]. The calling code then uses only clause[0] , effectively dropping the second clause:
let query = db.query[model].findFirst({
where: clause[0], // Only uses first element!
with: includes,
});
Impact
1.5.0-beta.3
Operating System:
Ubuntu 24.04.3 LTS
Kernel: 6.14.0-37-generic
Architecture: x86_64
Development Environment:
Node.js: v24.5.0
pnpm: 10.26.2
Git: 2.43.0
Backend
No response
No new interfaces are introduced.