Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prisma 4.11 breaks multilevel relation with compound primary keys (typings) #18173

Closed
lightningspirit opened this issue Mar 2, 2023 · 1 comment · Fixed by prisma/prisma-engines#3762
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/regression A reported bug in functionality that used to work before. team/client Issue for team Client. topic: client types Types in Prisma Client
Milestone

Comments

@lightningspirit
Copy link

lightningspirit commented Mar 2, 2023

Bug description

After upgrading from 4.10.1 to 4.11 the following query fails. Digging up the generated typings do not include tenant in neither mediaOnDocument nor mediaOnDocumentComment. Apparently the runtime client query still works as expected.

How to reproduce

Expected behavior

Upgrading should not break existing queries in generated typings.

Prisma information

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["fullTextSearch", "fullTextIndex", "extendedWhereUnique", "fieldReference", "filteredRelationCount", "orderByNulls", "metrics", "tracing"]
}

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
}

model Tenant {
  id                      String                   @id @default(cuid())
  media                   Media[]                  @relation("tenant")
  documents               Document[]               @relation("tenant")
  mediaOnDocuments        MediaOnDocument[]        @relation("tenant") @ignore
  mediaOnDocumentComments MediaOnDocumentComment[] @relation("tenant") @ignore

  @@map("tenants")
}

model Media {
  id        String            @default(cuid())
  documents MediaOnDocument[]
  tenant    Tenant            @relation("tenant", fields: [tenantId], references: [id])
  tenantId  String            @map("tenant_id")

  @@id([tenantId, id])
  @@map("media")
}

model Document {
  id       String            @default(cuid())
  media    MediaOnDocument[]
  tenant   Tenant            @relation("tenant", fields: [tenantId], references: [id])
  tenantId String            @map("tenant_id")

  @@id([tenantId, id])
  @@map("documents")
}

model MediaOnDocument {
  media      Media                    @relation(map: "media_on_documents_media_id", fields: [tenantId, mediaId], references: [tenantId, id])
  mediaId    String                   @map("media_id")
  document   Document                 @relation(map: "media_on_documents_document_id", fields: [tenantId, documentId], references: [tenantId, id])
  documentId String                   @map("document_id")
  comments   MediaOnDocumentComment[]
  tenant     Tenant                   @relation("tenant", fields: [tenantId], references: [id])
  tenantId   String                   @map("tenant_id")

  @@id([tenantId, mediaId, documentId])
  @@map("media_on_documents")
}

model MediaOnDocumentComment {
  id              String          @default(cuid())
  mediaOnDocument MediaOnDocument @relation(map: "media_on_documents_comment_id", fields: [tenantId, mediaId, documentId], references: [tenantId, mediaId, documentId])
  mediaId         String          @map("media_id")
  documentId      String          @map("document_id")
  tenant          Tenant          @relation("tenant", fields: [tenantId], references: [id])
  tenantId        String          @map("tenant_id")

  @@id([tenantId, id])
  @@map("media_on_document_comments")
}
const comment = await prisma.mediaOnDocumentComment.create({
  select: {
    id: true,
  },
  data: {
    mediaOnDocument: {
      connectOrCreate: {
        where: {
          tenantId_mediaId_documentId: {
            mediaId,
            documentId,
            tenantId,
          },
        },
        create: {
          document: {
            connect: {
              tenantId_id: {
                tenantId,
                id: documentId,
              },
            },
          },
          media: {
            connect: {
              tenantId_id: {
                tenantId,
                id: mediaId,
              },
            },
          },
          tenant: {
            connect: {
              id: tenantId,
            },
          },
        },
      },
    },
    tenant: {
      connect: {
        id: tenantId,
      },
    },
  },
})

Environment & setup

  • OS: macOS, Ubuntu
  • Database: MySQL, MariaDB
  • Node.js version: v18.7.0

Prisma Version

prisma                  : 4.11.0
@prisma/client          : 4.11.0
Current platform        : darwin
Query Engine (Node-API) : libquery-engine 8fde8fef4033376662cad983758335009d522acb (at ../../.npm/_npx/2778af9cee32ff87/node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine        : migration-engine-cli 8fde8fef4033376662cad983758335009d522acb (at ../../.npm/_npx/2778af9cee32ff87/node_modules/@prisma/engines/migration-engine-darwin)
Format Wasm             : @prisma/prisma-fmt-wasm 4.11.0-57.8fde8fef4033376662cad983758335009d522acb
Default Engines Hash    : 8fde8fef4033376662cad983758335009d522acb
Studio                  : 0.483.0
Preview Features        : fullTextSearch, fullTextIndex, tracing, metrics, orderByNulls, filteredRelationCount, fieldReference, deno, extendedWhereUnique
@lightningspirit lightningspirit added the kind/bug A reported bug. label Mar 2, 2023
@lightningspirit lightningspirit changed the title Prisma 4.11 breaks multilevel indirection with compound primary keys Prisma 4.11 breaks multilevel relation with compound primary keys (typings) Mar 2, 2023
@janpio janpio added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. topic: client types Types in Prisma Client team/client Issue for team Client. bug/2-confirmed Bug has been reproduced and confirmed. kind/regression A reported bug in functionality that used to work before. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. labels Mar 2, 2023
@janpio
Copy link
Member

janpio commented Mar 2, 2023

Can confirm:

PS C:\Users\Jan\Documents\throwaway\18173> npx ts-node .\script.ts
C:\Users\Jan\Documents\throwaway\18173\node_modules\ts-node\src\index.ts:859
    return new TSError(diagnosticText, diagnosticCodes, diagnostics);
           ^
TSError: ⨯ Unable to compile TypeScript:
script.ts:40:13 - error TS2322: Type '{ document: { connect: { tenantId_id: { tenantId: string; id: string; }; }; }; media: { connect: { tenantId_id: { tenantId: string; id: string; }; }; }; tenant: { connect: { id: string; }; }; }' is not assignable to type '(Without<MediaOnDocumentCreateWithoutCommentsInput<$PrismaModel>, MediaOnDocumentUncheckedCreateWithoutCommentsInput> & MediaOnDocumentUncheckedCreateWithoutCommentsInput) | (Without<...> & MediaOnDocumentCreateWithoutCommentsInput<...>)'.
  Object literal may only specify known properties, but 'tenant' does not exist in type 'Without<MediaOnDocumentUncheckedCreateWithoutCommentsInput, MediaOnDocumentCreateWithoutCommentsInput<$PrismaModel>> & MediaOnDocumentCreateWithoutCommentsInput<...>'. Did you mean to write 'tenantId'?

 40             tenant: {
                ~~~~~~~~~
 41               connect: {
    ~~~~~~~~~~~~~~~~~~~~~~~~
...
 43               },
    ~~~~~~~~~~~~~~~~
 44             },
    ~~~~~~~~~~~~~

    at createTSError (C:\Users\Jan\Documents\throwaway\18173\node_modules\ts-node\src\index.ts:859:12)
    at reportTSError (C:\Users\Jan\Documents\throwaway\18173\node_modules\ts-node\src\index.ts:863:19)
    at getOutput (C:\Users\Jan\Documents\throwaway\18173\node_modules\ts-node\src\index.ts:1077:36)
    at Object.compile (C:\Users\Jan\Documents\throwaway\18173\node_modules\ts-node\src\index.ts:1433:41)
    at Module.m._compile (C:\Users\Jan\Documents\throwaway\18173\node_modules\ts-node\src\index.ts:1617:30)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Object.require.extensions.<computed> [as .ts] (C:\Users\Jan\Documents\throwaway\18173\node_modules\ts-node\src\index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Function.Module._load (node:internal/modules/cjs/loader:878:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
  diagnosticCodes: [ 2322 ]
}

In 4.10.1 this query was executed without problems.

Reproduction repository: https://github.com/janpio/18173

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/regression A reported bug in functionality that used to work before. team/client Issue for team Client. topic: client types Types in Prisma Client
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants