Skip to content

fix(drizzle-orm): is() crash on objects with null prototype#5625

Open
markacola wants to merge 1 commit into
drizzle-team:mainfrom
ligantic:fix/is-null-object-prototype
Open

fix(drizzle-orm): is() crash on objects with null prototype#5625
markacola wants to merge 1 commit into
drizzle-team:mainfrom
ligantic:fix/is-null-object-prototype

Conversation

@markacola
Copy link
Copy Markdown

What

Adds optional chaining (?.) to the Object.getPrototypeOf(value) call in the is() function in entity.ts.

Why

Object.getPrototypeOf() returns null for objects created with Object.create(null). Without optional chaining, accessing .constructor on null throws:

TypeError: Cannot read properties of null (reading 'constructor')

This affects insert and update operations when a user passes an Object.create(null)-based value (e.g. a JSON column value), because the query builder calls is(colValue, SQL) on each column value:

// This crashes without the fix
const jsonValue = Object.create(null);
jsonValue.key = 'value';

db.insert(myTable).values({ name: 'test', data: jsonValue });
db.update(myTable).set({ data: jsonValue }).where(eq(myTable.id, 1));

Changes

  • entity.ts — Changed Object.getPrototypeOf(value).constructor to Object.getPrototypeOf(value)?.constructor on line 29.
  • is.test.ts — Added 3 test cases:
    • is() returns false (instead of throwing) for Object.create(null) values
    • Insert query building succeeds when a column value is an Object.create(null) object
    • Update query building succeeds when a column value is an Object.create(null) object

All 3 tests produce TypeError: Cannot read properties of null (reading 'constructor') without the fix.

Object.getPrototypeOf() returns null for objects created with Object.create(null). Without optional chaining, accessing .constructor on null throws a TypeError. This affects insert and update operations when a user passes an Object.create(null)-based value (e.g. for a JSON column), since the query builder calls is(colValue, SQL) on each value.
@markacola markacola force-pushed the fix/is-null-object-prototype branch from 07bb13c to 570c97b Compare April 11, 2026 13:39
@markacola markacola changed the title Fix is() crash on objects with null prototype fix(drizzle-orm): is() crash on objects with null prototype Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant