Maximum call stack size exceeded: orderSelectedFields

I'm migrating from Prisma, and trying to replace an aggregate query. I'm getting an error with the following query, which is—as far as I can tell—right from the documentation on aggregate queries: https://orm.drizzle.team/docs/crud#aggregations

await db
  .select({
    total: sql<number>`sum(${t.tokenUse.total})`,
  })
  .from(t.tokenUse)
  .where(
    and(
      eq(t.tokenUse.userId, user.id),
      gt(t.tokenUse.createdAt, startOfToday),
      eq(t.tokenUse.userTriggered, 1),
    ),
  )
  .groupBy(t.tokenUse.userId)


The error looks like an infinite loop

@muse/nextjs:dev: RangeError: Maximum call stack size exceeded
@muse/nextjs:dev:     at Array.values (<anonymous>)
@muse/nextjs:dev:     at ./node_modules/drizzle-orm/alias-cf8e03cd.mjs:218:42
@muse/nextjs:dev:     at Array.reduce (<anonymous>)
@muse/nextjs:dev:     at orderSelectedFields (./node_modules/drizzle-orm/alias-cf8e03cd.mjs:218:35)


Using the most recent version of Drizzle (0.28.6) and the Planetscale adapter.

Any thoughts on what's going on?
Was this page helpful?