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.8 produces conflicting typescript types for custom many to many relations #17005

Closed
hayes opened this issue Dec 23, 2022 · 6 comments · Fixed by #17101
Closed

Prisma 4.8 produces conflicting typescript types for custom many to many relations #17005

hayes opened this issue Dec 23, 2022 · 6 comments · Fixed by #17101
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. kind/regression A reported bug in functionality that used to work before. team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: client types Types in Prisma Client topic: m:n many-to-many relations
Milestone

Comments

@hayes
Copy link
Contributor

hayes commented Dec 23, 2022

Bug description

prisma 4.8 is producing multiple typescript type definitions with the same name for a fairly common naming pattern for a custom many to many relation

How to reproduce

  1. clone https://github.com/hayes/prisma-4.8-generator-bug
  2. run npm install
  3. run npm geneate
  4. run npm type

Expected behavior

Type checking the client should not cause errors, types should all have unique names

Prisma information

datasource db {
  provider = "sqlite"
  url      = "file:./dev.db"
}

generator client {
  provider = "prisma-client-js"
  output   = "../client"
}

/// Model for Posts!
model Post {
  id Int @id @default(autoincrement())
  media PostMedia[]
}

model Media {
  id Int @id @default(autoincrement())
  posts PostMedia[]
}

model PostMedia {
  id      Int   @id @default(autoincrement())
  post    Post  @relation(fields: [postId], references: [id])
  media   Media @relation(fields: [mediaId], references: [id])
  postId  Int
  mediaId Int
  @@unique([postId, mediaId])
}
// Add your code using Prisma Client

Environment & setup

  • OS: macOS
  • Database: sqlite
  • Node.js version: 16.17

Prisma Version

prisma                  : 4.8.0
@prisma/client          : 4.8.0
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine d6e67a83f971b175a593ccc12e15c4a757f93ffe (at node_modules/.pnpm/@prisma+engines@4.8.0/node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli d6e67a83f971b175a593ccc12e15c4a757f93ffe (at node_modules/.pnpm/@prisma+engines@4.8.0/node_modules/@prisma/engines/migration-engine-darwin-arm64)
Introspection Engine    : introspection-core d6e67a83f971b175a593ccc12e15c4a757f93ffe (at node_modules/.pnpm/@prisma+engines@4.8.0/node_modules/@prisma/engines/introspection-engine-darwin-arm64)
Format Binary           : prisma-fmt d6e67a83f971b175a593ccc12e15c4a757f93ffe (at node_modules/.pnpm/@prisma+engines@4.8.0/node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
Format Wasm             : @prisma/prisma-fmt-wasm 4.8.0-61.d6e67a83f971b175a593ccc12e15c4a757f93ffe
Default Engines Hash    : d6e67a83f971b175a593ccc12e15c4a757f93ffe
Studio                  : 0.479.0
@hayes hayes added the kind/bug A reported bug. label Dec 23, 2022
@jkomyno jkomyno added bug/2-confirmed Bug has been reproduced and confirmed. team/client Issue for team Client. labels Dec 27, 2022
@jkomyno
Copy link
Contributor

jkomyno commented Dec 27, 2022

I can confirm this issue happens with prisma@4.8.0, but not with prisma@4.7.1.

@jkomyno jkomyno added the kind/regression A reported bug in functionality that used to work before. label Jan 2, 2023
@Jolg42 Jolg42 added topic: client types Types in Prisma Client tech/typescript Issue for tech TypeScript. topic: m:n many-to-many relations labels Jan 2, 2023
@Jolg42
Copy link
Member

Jolg42 commented Jan 2, 2023

This looks related to #16844 @SevInf

Released in our internal version 4.8.0-dev.70
https://buildkite.com/prisma/release-prisma-typescript/builds/7780#01852ecf-dbdc-4a4d-ac8d-c8ea399483a9

4.8.0-dev.69 I can see

  /**
   * PostMedia without action
   */
  export type PostMediaArgs = {
    /**
     * Select specific fields to fetch from the PostMedia
     * 
    **/
    select?: PostMediaSelect | null
    /**
     * Choose, which related nodes to fetch as well.
     * 
    **/
    include?: PostMediaInclude | null
  }

and since 4.8.0-dev.70

// line 1907

  /**
   * Post.media
   */
  export type PostMediaArgs = {
    /**
     * Select specific fields to fetch from the PostMedia
     * 
    **/
    select?: PostMediaSelect | null
    /**
     * Choose, which related nodes to fetch as well.
     * 
    **/
    include?: PostMediaInclude | null
    where?: PostMediaWhereInput
    orderBy?: Enumerable<PostMediaOrderByWithRelationInput>
    cursor?: PostMediaWhereUniqueInput
    take?: number
    skip?: number
    distinct?: Enumerable<PostMediaScalarFieldEnum>
  }

// line 3967

  /**
   * PostMedia without action
   */
  export type PostMediaArgs = {
    /**
     * Select specific fields to fetch from the PostMedia
     * 
    **/
    select?: PostMediaSelect | null
    /**
     * Choose, which related nodes to fetch as well.
     * 
    **/
    include?: PostMediaInclude | null
  }

@SevInf SevInf self-assigned this Jan 2, 2023
SevInf added a commit that referenced this issue Jan 2, 2023
Since 4.8.0, we generate explicit types for model fields args, not only
for top level queries. Naming we choose for it, `ModelFieldArgs` can
clash with existing types if `ModelField` type also exists in the
schema. To fix it, this PR changes naming scheme to `Model$fieldArgs`.
Since `$` can not be used in type name, this new naming scheme is
guaranteed not to clash with anything.

Fix #17005
SevInf added a commit that referenced this issue Jan 2, 2023
Since 4.8.0, we generate explicit types for model fields args, not only
for top level queries. Naming we choose for it, `ModelFieldArgs` can
clash with existing types if `ModelField` type also exists in the
schema. To fix it, this PR changes naming scheme to `Model$fieldArgs`.
Since `$` can not be used in type name, this new naming scheme is
guaranteed not to clash with anything.

Fix #17005
@Jolg42 Jolg42 added this to the 4.9.0 milestone Jan 3, 2023
SevInf added a commit that referenced this issue Jan 4, 2023
Since 4.8.0, we generate explicit types for model fields args, not only
for top level queries. Naming we choose for it, `ModelFieldArgs` can
clash with existing types if `ModelField` type also exists in the
schema. To fix it, this PR changes naming scheme to `Model$fieldArgs`.
Since `$` can not be used in type name, this new naming scheme is
guaranteed not to clash with anything.

Fix #17005
SevInf added a commit that referenced this issue Jan 5, 2023
for top level queries. Naming we choose for it, `ModelFieldArgs` can
clash with existing types if `ModelField` type also exists in the
schema. To fix it, this PR changes naming scheme to `Model$fieldArgs`.
Since `$` can not be used in type name, this new naming scheme is
guaranteed not to clash with anything.

Fix #17005

Co-authored-by: Joël Galeran <Jolg42@users.noreply.github.com>
Co-authored-by: Daniel Starns <danielstarns@hotmail.com>
SevInf added a commit that referenced this issue Jan 5, 2023
Since 4.8.0, we generate explicit types for model fields args, not only
for top level queries. Naming we choose for it, `ModelFieldArgs` can
clash with existing types if `ModelField` type also exists in the
schema. To fix it, this PR changes naming scheme to `Model$fieldArgs`.
Since `$` can not be used in type name, this new naming scheme is
guaranteed not to clash with anything.

Fix #17005

Co-authored-by: Joël Galeran <Jolg42@users.noreply.github.com>
Co-authored-by: Daniel Starns <danielstarns@hotmail.com>
SevInf added a commit that referenced this issue Jan 5, 2023
…ly (#17101)

for top level queries. Naming we choose for it, `ModelFieldArgs` can
clash with existing types if `ModelField` type also exists in the
schema. To fix it, this PR changes naming scheme to `Model$fieldArgs`.
Since `$` can not be used in type name, this new naming scheme is
guaranteed not to clash with anything.

Fix #17005

Co-authored-by: Joël Galeran <Jolg42@users.noreply.github.com>
Co-authored-by: Daniel Starns <danielstarns@hotmail.com>
@SevInf
Copy link
Contributor

SevInf commented Jan 5, 2023

Note: fix will be published as 4.8.1 version today

@serg06
Copy link

serg06 commented Jan 5, 2023

Is this only for explicit relations or for implicit ones as well?

SevInf added a commit that referenced this issue Jan 12, 2023
…ly (#17101)

for top level queries. Naming we choose for it, `ModelFieldArgs` can
clash with existing types if `ModelField` type also exists in the
schema. To fix it, this PR changes naming scheme to `Model$fieldArgs`.
Since `$` can not be used in type name, this new naming scheme is
guaranteed not to clash with anything.

Fix #17005

Co-authored-by: Joël Galeran <Jolg42@users.noreply.github.com>
Co-authored-by: Daniel Starns <danielstarns@hotmail.com>
@HugoxSaraiva
Copy link

Hi, can we reopen this issue, or should I open a new one?

I'm getting the same error on prisma v4.16.2, but with a different schema definition.
I've created a repo to reproduce this error on 4.16.2:
https://github.com/HugoxSaraiva/prisma-4.16-generator-bug

Node version: v16.19.1

Prisma version:

prisma                  : 4.16.2
@prisma/client          : 4.16.2
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine 4bc8b6e1b66cb932731fb1bdbbc550d1e010de81 (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli 4bc8b6e1b66cb932731fb1bdbbc550d1e010de81 (at node_modules/@prisma/engines/migration-engine-darwin-arm64)
Format Wasm             : @prisma/prisma-fmt-wasm 4.16.1-1.4bc8b6e1b66cb932731fb1bdbbc550d1e010de81
Default Engines Hash    : 4bc8b6e1b66cb932731fb1bdbbc550d1e010de81
Studio                  : 0.484.0

@SevInf
Copy link
Contributor

SevInf commented Aug 21, 2023

@HugoxSaraiva I took a look at your repository and this specific issue have been fixed in 5.1, I'd suggest updating.

Generally speaking, the chance that the issue you are experiencing is exactly the same as the one that was fixed 7 month ago are pretty low, even if the error message seems similar. So, I'd always advice to check latest Prisma version first and if you still have the problem then open a new issue, please.

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/bug A reported bug. kind/regression A reported bug in functionality that used to work before. team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: client types Types in Prisma Client topic: m:n many-to-many relations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants