drizzle-team / drizzle-team/drizzle-orm

[BUG]: ExtraConfigColumn.getSQLType() calls itself — stack overflow for any column accessed in pgTable's extra-config callback

Open Beginner friendly
#6,050 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Report hasn't been filed before.

- [X] I have verified that the bug I'm about to report hasn't been filed before.

### What version of `drizzle-orm` are you using?

0.45.2

### What version of `drizzle-kit` are you using?

none — not involved; this reproduces with drizzle-orm alone

### Other packages

_No response_

### Describe the Bug

`ExtraConfigColumn` in `pg-core/columns/common.ts` overrides `getSQLType()` with a method that calls itself:

```ts
override getSQLType(): string {
return this.getSQLType();
}
```

Every column handed to `pgTable`'s third argument (the extra-config callback) is wrapped as an `ExtraConfigColumn`, so calling `getSQLType()` on any of those columns throws `RangeError: Maximum call stack size exceeded`. The same call on the unwrapped column works fine.

Reproduction (no driver, no drizzle-kit):

```js
const { pgTable, integer, getTableConfig } = require('drizzle-orm/pg-core')

let captured
const users = pgTable('users', { id: integer('id').primaryKey() }, (t) => {
captured = t.id
return []
})

getTableConfig(users) // runs the extra-config callback

console.log(users.id.getSQLType()) // "integer"
console.log(captured.getSQLType()) // RangeError: Maximum call stack size exceeded
```

Desired result: `captured.getSQLType()` returns `"integer"`, same as the unwrapped column.

The override presumably meant to delegate to the parent:

```ts
override getSQLType(): string {
return super.getSQLType();
}
```

The line dates to 3d5d8d5 ("Change an api for indexes pg"), where the class was introduced, and is still present on `main` and in the published `1.0.0-rc.4` — so it affects both the 0.x and 1.0 lines. It has presumably gone unnoticed because drizzle-kit and the built-in index builders read column config directly rather than calling `getSQLType()`; it surfaces when library code derives expression-index DDL from the columns it receives in the callback. We hit it in [`@cipherstash/stack-drizzle`](https://github.com/cipherstash/stack/tree/main/packages/stack-drizzle), in a helper that emits functional indexes for encrypted columns — [our workaround](https://github.com/cipherstash/stack/blob/239f79b51dc6c7070ae6b150190856c1799faf6f/packages/stack-drizzle/src/v3/column.ts#L83-L109) reads `customTypeParams.dataType(...)` off the column config instead.

Contributor guide

Open the contributing guide

Research direction

Start in pg-core/columns/common.ts and inspect ExtraConfigColumn.getSQLType(), comparing it with the parent column implementation. Reproduce the issue with the callback example from the report, then verify that getSQLType() on the captured extra-config column returns "integer" without a stack overflow.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, typescript
Domain
database
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.