Skip to content

drizzle MySqlSelectBase: inherited .then resolves to undefined under Perry (await returns the builder) #2159

@proggeramlug

Description

@proggeramlug

Summary

await <drizzle MySqlSelectBase instance> returns the builder object itself instead of resolving to the query result. The instance has .then inherited from drizzle-orm's QueryPromise base class (via 4+ levels of inheritance), but under Perry the property lookup instance.then returns undefined — so await doesn't see a thenable and just unwraps to the original value.

.execute() on the same instance resolves correctly and is the in-fixture workaround. Found while landing the drizzle-mysql fixture for #489.

Repro

In tests/release/packages/drizzle-mysql/entry.ts, replace any line of the form:

const all = await db.select().from(users).execute();

with the idiomatic drizzle form:

const all = await db.select().from(users);

Perry prints count=undefined then SIGBUS'es; Bun (bun --conditions=perry run entry.ts) and Node both print count=2. Verified by inserting diagnostic logs:

sel:  object MySqlSelectBuilder
from: object MySqlSelectBase hasThen= undefined hasExecute= function

So _from.execute resolves to a function but _from.then (inherited from QueryPromise through TypedQueryBuilder → MySqlSelectQueryBuilderBase → MySqlSelectBase) resolves to undefined.

What I tried to minimize (and couldn't)

These all work correctly under Perry — none reproduces the .then === undefined shape:

  • 3+ level user-class inheritance with .then defined on the root.
  • Same, in a compilePackages .js package.
  • Same with static [entityKind] = "..." (computed symbol field) on every class.
  • 5-level chain Root → TQB → QBB → SQB → SBase with .then only on Root, static [entityKind] on every level.

Something more specific in drizzle's class graph (likely mixins, decorators, or constructor-injected fields touching then) is the trigger. The drizzle case is reproducible by reverting the .execute() calls in the fixture entry, so this issue's repro lives there.

Impact

Affects every idiomatic drizzle-orm query: await db.select().from(x), await db.update(x).set(...), etc. Currently worked around with explicit .execute() in the drizzle-mysql fixture; fixing this lets users write idiomatic upstream drizzle code unchanged. Likely benefits other thenable libraries with deep mixin-style inheritance.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingparityNode.js compatibility / parity gaps

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions