drizzle-team / drizzle-team/drizzle-orm

[BUG]: `.get()` with `.returning()` returns malformed object

Open
#5,775 3 comments 0 reactions 0 assignees View on GitHub
bug bug/cant-reproduce
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

## Bug: `.get()` with `.returning()` returns malformed object + incorrect TypeScript types

### Description

Using `.get()` after `.returning()` on an insert query returns a malformed object where all columns are `undefined` and the `id` field contains an array of the row's actual values. Dates also come back as `Invalid Date`.

Using `[0]` index on the same query works correctly.

To make it worse, **TypeScript types `.get()` as returning the correct shaped object** — so there's no compile-time warning. The types and the actual runtime value silently disagree.

### Reproduction

```ts
// ✅ Works correctly
const row = (await db.insert(table).values(data).returning())[0];
// { id: 1, name: "foo", createdAt: 2026-01-01T00:00:00.000Z }

// ❌ Broken at runtime, but TypeScript shows no error
const row = await db.insert(table).values(data).returning().get();
// TS thinks: { id: number, name: string, createdAt: Date }
// Actual: { id: [1, "foo", ...], name: undefined, createdAt: Invalid Date }

// So this compiles fine but fails silently at runtime:
console.log(row.name.toUpperCase()); // TypeError: Cannot read properties of undefined
console.log(row.createdAt.toISOString()); // TypeError: Invalid Date
```

### Expected behavior

Both should return the same result: `{ id: 1, name: "foo", createdAt: 2026-01-01T00:00:00.000Z }`

If `.get()` is not supported with `.returning()`, it should either be typed as `never` or throw an explicit error instead of returning a malformed object silently.

### Actual behavior

`.get()` returns an object where:
- All columns are `undefined`
- `id` contains an array of the row's actual values (as if the tuple wasn't mapped to columns)
- Date columns return `Invalid Date`

### Why this is dangerous

Since TypeScript reports no type error, developers have no indication something is wrong. The bug only surfaces at runtime, and only if the values are actually used — making it easy to ship silently broken code.

### Environment

- Driver: libsql / better-sqlite3
- ORM: drizzle-orm (please fill in your version)

### Additional context

`.get()` likely works correctly for plain `.select()` queries but skips the column mapping step when used with `.returning()`. Both the runtime behavior and the TypeScript types need to be fixed.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.