Skip to content

[Prisma 8 - MongoDB] - Polymorphic Collections give runtime error when extending with no fields #30310

Description

@jochemvanweelde

Package and version

8.0.0-rc.11

What happened?

When generating schema with Polymorphic Collections with model with no extra fields extended from base, will give this runtime error upon querying.

StructuredError: Contract structural validation failed: domain.namespaces.unbound.models.DealPartnerAttachment.fields must be an object (was missing)

What did you expect to happen?

One of these options:

  • Generation error: Disallowing extending model with no extra fields
  • No error on query: Allowing the generation of a discriminator type where only the base fields are available, with no extra fields. (See reproduction for example)

Minimal reproduction

Given this example model of a document.

model Document {
  id        ObjectId @id @map("_id")
  createdAt DateTime
  updatedAt DateTime

  blobUrl String

  @@map("documents")
}

Let's say we have three different documents: Quote, Invoice and Generic. Both Quote and Invoice extend the base model with quotationNumber and invoiceNumber respectively. Generic has no extra fields. Doing this with the new discriminator feature is not possible:

model Document {
  id        ObjectId @id @map("_id")
  createdAt DateTime
  updatedAt DateTime

  blobUrl String

   type String

  @@discriminator(type)
  @@map("documents")
}

model Quote {
  quotationNumber String

  @@base(DealAttachment, "QUOTE")
}

model Invoice {
  invoiceNumber String

  @@base(DealAttachment, "INVOICE")
}

The above code snippet will generate a type where Document.type can only be QUOTE or INVOICE.
adding the Generic document type:

model GenericDocument {
  // No extended fields

  @@base(DealAttachment, "GENERIC")
}

This will correctly generate the schema but will result in a run time contract validation error: StructuredError: Contract structural validation failed: domain.namespaces.unbound.models.Document.fields must be an object (was missing). The generated type is correct.

Environment

MongoDB 8.0.29 Atlas
Node 24.15.0
NextJS 16.3

Additional context

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/1-unconfirmedBug should have enough information for reproduction, but confirmation has not happened yet.kind/bugA reported bug.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions