#30270·Prisma

bug(contract): PSL index sort syntax @@index([field(sort: Desc)]) fails with "Expected a field name"

Author: TahaHamdy-MernDevCreated Sep 12, 2026Updated Sep 12, 2026

Package and version

[email protected] @prisma/[email protected]

What happened?

When specifying an index with a sort direction in contract.prisma using the familiar Prisma schema syntax:

@@index([created_at(sort: Desc)])

prisma contract emit fails during contract resolution with:

✘ [CONTRACT.SOURCE_LOAD_FAILED] Failed to resolve contract source
  why: PSL to SQL contract interpretation failed
  code: "PSL_INVALID_ATTRIBUTE_SYNTAX"
  message: "Expected a field name"

In @prisma/orm-family-sql / @prisma/orm-framework (psl-parser.mjs), indexModelSpec parses positional fields with list(fieldRef("self")), which strictly expects bare IdentifierAst tokens. Because created_at(sort: Desc) is parsed as a FunctionCallAst, it fails with Expected a field name.

What did you expect to happen?

Either:

  1. (sort: Desc) and (sort: Asc) field annotations inside @@index([ ... ]) should be supported in Prisma 8 PSL (parity with Prisma 7), OR
  2. If explicit sort direction in field lists is intentionally unsupported, the parser should provide a descriptive diagnostic (e.g. "Sort options are not supported inside field lists; use expression: ... instead") rather than the cryptic "Expected a field name" error.

Minimal reproduction

  1. Create a minimal contract.prisma:
model Item {
  id         Uuid              @id @default(uuid(7))
  created_at TimestamptzString @default(now())

  @@index([created_at(sort: Desc)])
  @@map("items")
}
  1. Run:
prisma contract emit

Environment

  • Node: v24.20.0
  • OS: Linux x86_64
  • Package manager: pnpm
  • Database: Postgres (@prisma/orm-postgres)

Additional context

Running prisma contract emit --json produces the following structured error:

{
  "code": "CONTRACT.SOURCE_LOAD_FAILED",
  "summary": "Failed to resolve contract source",
  "why": "PSL to SQL contract interpretation failed",
  "meta": {
    "diagnostics": [
      {
        "code": "PSL_INVALID_ATTRIBUTE_SYNTAX",
        "message": "Expected a field name",
        "sourceId": "./src/prisma/contract/contract.prisma"
      }
    ]
  }
}

Current workarounds:

  • Use standard single-column index: @@index([created_at])
  • Use SQL expression: @@index(expression: "created_at DESC", name: "items_created_at_desc_idx")