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

Type conflict when naming a table {something} and a second table {something}Result #16940

Closed
doflo-dfa opened this issue Dec 21, 2022 · 1 comment · Fixed by #20184
Closed
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/engines Issue for tech Engines. topic: client types Types in Prisma Client topic: type-clash
Milestone

Comments

@doflo-dfa
Copy link

doflo-dfa commented Dec 21, 2022

Bug description

There is now a conflict when naming a table {something} and a second table {something}Result

in our case we had Credentials and CredentialsResult both of which referenced each other.

The client generation will create a typescript files that has two conflicting type interfaces named the same thing

How to reproduce

name a table {something} and a second table {something}Result

Expected behavior

That the client generation would namespace the types or that the docs would mark Result as a reserved word not to be used in the table names

Prisma information

// Add your schema.prisma
model Credential {
  id          String                @id @default(cuid())
  createdAt   DateTime              @default(now())
  updatedAt   DateTime              @updatedAt
  namespaceId String
  development Boolean?
  system      Boolean?              @default(false)
  Namespace   Namespace             @relation(fields: [namespaceId], references: [id])
  Team        Team?                 @relation(fields: [teamId], references: [id])
  User        User?                 @relation(fields: [userId], references: [id])
  results     CredentialResult[] 
  Elements    Element[]             @relation("selectedCredential")
}

model CredentialResult {
  id           String     @id @default(cuid())
  createdAt    DateTime   @default(now())
  updatedAt    DateTime   @updatedAt
  pass         Boolean
  credentialId String
  Credential   Credential @relation(fields: [credentialId], references: [id])
}
// Add your code using Prisma Client

Environment & setup

  • OS: macOS
  • Database: PostgreSQL
  • Node.js version: v16.15.1

Prisma Version

prisma                  : 4.8.0
@prisma/client          : 4.8.0
Current platform        : darwin
Query Engine (Node-API) : libquery-engine d6e67a83f971b175a593ccc12e15c4a757f93ffe (at node_modules/prisma/node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine        : migration-engine-cli d6e67a83f971b175a593ccc12e15c4a757f93ffe (at node_modules/prisma/node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine    : introspection-core d6e67a83f971b175a593ccc12e15c4a757f93ffe (at node_modules/prisma/node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary           : prisma-fmt d6e67a83f971b175a593ccc12e15c4a757f93ffe (at node_modules/prisma/node_modules/@prisma/engines/prisma-fmt-darwin)
Format Wasm             : @prisma/prisma-fmt-wasm 4.8.0-61.d6e67a83f971b175a593ccc12e15c4a757f93ffe
Default Engines Hash    : d6e67a83f971b175a593ccc12e15c4a757f93ffe
Studio                  : 0.479.0
Preview Features        : filterJson

@doflo-dfa doflo-dfa added the kind/bug A reported bug. label Dec 21, 2022
@jkomyno jkomyno added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. tech/engines Issue for tech Engines. team/schema Issue for team Schema. bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. team/client Issue for team Client. and removed bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. team/schema Issue for team Schema. labels Dec 21, 2022
@jkomyno jkomyno changed the title conflict when naming a table {something} and a second table {something}Result Type conflict when naming a table {something} and a second table {something}Result Dec 21, 2022
SevInf added a commit that referenced this issue Jul 12, 2023
In some cases, generated types for one of the models will clash with
generated types for another. In that case, we would generate duplicate
type.
This PR fixes this: approach is very different to namespaces proposal I
shared earlier. Turns out, most of the conflicts are solved by just
renaming default args types from `ModelArgs` to `ModelDefaultArgs`.
Deperecated alias for an old name would still be created if it does not
conflict.
Somewhat different case is `Payload` type. First, they are created at
top level of the file, rather then in `Prisma` namespace. @millsp and I
agreed that thouse types are not public, so it is safe to move them to
namespace and rename them. So, `UserPayload` would now become
`Prisma.$UserPayload`. This allows to both use `UserPayload` as a model
name as well as use `Batch` as a model name (we have built-in
`BatchPayload` type that is unrelated to aforementioned `Payload`
types).

Fix #19967
Fix #18902
Fix #16940
Fix #9568
Fix #7518
SevInf added a commit that referenced this issue Jul 12, 2023
In some cases, generated types for one of the models will clash with
generated types for another. In that case, we would generate duplicate
type.
This PR fixes this: approach is very different to namespaces proposal I
shared earlier. Turns out, most of the conflicts are solved by just
renaming default args types from `ModelArgs` to `ModelDefaultArgs`.
Deperecated alias for an old name would still be created if it does not
conflict.
Somewhat different case is `Payload` type. First, they are created at
top level of the file, rather then in `Prisma` namespace. @millsp and I
agreed that thouse types are not public, so it is safe to move them to
namespace and rename them. So, `UserPayload` would now become
`Prisma.$UserPayload`. This allows to both use `UserPayload` as a model
name as well as use `Batch` as a model name (we have built-in
`BatchPayload` type that is unrelated to aforementioned `Payload`
types).

Fix #19967
Fix #18902
Fix #16940
Fix #9568
Fix #7518
SevInf added a commit that referenced this issue Jul 18, 2023
In some cases, generated types for one of the models will clash with
generated types for another. In that case, we would generate duplicate
type.
This PR fixes this: approach is very different to namespaces proposal I
shared earlier. Turns out, most of the conflicts are solved by just
renaming default args types from `ModelArgs` to `ModelDefaultArgs`.
Deperecated alias for an old name would still be created if it does not
conflict.
Somewhat different case is `Payload` type. First, they are created at
top level of the file, rather then in `Prisma` namespace. @millsp and I
agreed that thouse types are not public, so it is safe to move them to
namespace and rename them. So, `UserPayload` would now become
`Prisma.$UserPayload`. This allows to both use `UserPayload` as a model
name as well as use `Batch` as a model name (we have built-in
`BatchPayload` type that is unrelated to aforementioned `Payload`
types).

Fix #19967
Fix #18902
Fix #16940
Fix #9568
Fix #7518
SevInf added a commit that referenced this issue Jul 18, 2023
In some cases, generated types for one of the models will clash with
generated types for another. In that case, we would generate duplicate
type.
This PR fixes this: approach is very different to namespaces proposal I
shared earlier. Turns out, most of the conflicts are solved by just
renaming default args types from `ModelArgs` to `ModelDefaultArgs`.
Deperecated alias for an old name would still be created if it does not
conflict.
Somewhat different case is `Payload` type. First, they are created at
top level of the file, rather then in `Prisma` namespace. @millsp and I
agreed that thouse types are not public, so it is safe to move them to
namespace and rename them. So, `UserPayload` would now become
`Prisma.$UserPayload`. This allows to both use `UserPayload` as a model
name as well as use `Batch` as a model name (we have built-in
`BatchPayload` type that is unrelated to aforementioned `Payload`
types).

Fix #19967
Fix #18902
Fix #16940
Fix #9568
Fix #7518
@Jolg42 Jolg42 added this to the 5.1.0 milestone Jul 18, 2023
@Jolg42 Jolg42 added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Jul 18, 2023
@SevInf
Copy link
Contributor

SevInf commented Jul 18, 2023

This issue is now fixed and the fix will be published as a part of 5.1 release. If you'd like to verify fix earlier, you can use dev snapshot 5.1.0-dev.24. We don't recommend using it in production, but it should be enough to verify the fix.

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. team/client Issue for team Client. tech/engines Issue for tech Engines. topic: client types Types in Prisma Client topic: type-clash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants