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 name clash when Model and ModelUpdate is defined in the schema #9568

Closed
pantharshit00 opened this issue Oct 2, 2021 · 4 comments · Fixed by #20184
Closed

Type name clash when Model and ModelUpdate is defined in the schema #9568

pantharshit00 opened this issue Oct 2, 2021 · 4 comments · Fixed by #20184
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: generator topic: reserved words See https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#naming-conventions topic: type-clash
Milestone

Comments

@pantharshit00
Copy link
Contributor

Bug description

Prior context: #9421

We are encountering a conflict in our generated typing when a model named User for example is defined along with UserUpdate, it will generate invalid type that won't compile.

How to reproduce

Generate client with the following model:

generator client {
  provider = "prisma-client-js"
}

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


model User {
  id String @id @default(cuid())
}

model UserUpdate {
  id String @id @default(cuid())
}

Expected behavior

Client should generate valid types for any valid schema

Prisma information

See above in "how to reproduce"

Environment & setup

  • OS: Windows 10
  • Database: Postgres
  • Node.js version: 14.17.0

Prisma Version

Environment variables loaded from prisma\.env
prisma                  : 3.2.0-dev.48
@prisma/client          : 3.2.0-dev.48
Current platform        : windows
Query Engine (Node-API) : libquery-engine a153cf0caf0e5e24b69198dcdc040568256a1124 (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine        : migration-engine-cli a153cf0caf0e5e24b69198dcdc040568256a1124 (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine    : introspection-core a153cf0caf0e5e24b69198dcdc040568256a1124 (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary           : prisma-fmt a153cf0caf0e5e24b69198dcdc040568256a1124 (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash    : a153cf0caf0e5e24b69198dcdc040568256a1124
Studio                  : 0.435.0
@pantharshit00 pantharshit00 added kind/bug A reported bug. bug/2-confirmed Bug has been reproduced and confirmed. process/candidate team/client Issue for team Client. topic: generator labels Oct 2, 2021
@matthewmueller matthewmueller added the topic: reserved words See https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#naming-conventions label Feb 1, 2022
@andrewpap22
Copy link

andrewpap22 commented Aug 29, 2022

Any news on this?

We're getting with @Learus the same error, when trying to build for production, while on dev environment everything seems to be working properly.

The error:

#0 63.80 ../node_modules/.prisma/client/index.d.ts:10331:62
#0 63.80 Type error: Type 'S["include"][P]' does not satisfy the constraint 'boolean | AccountssArgs | null | undefined'.
#0 63.80   Type 'S["include"]["created_by_account"]' is not assignable to type 'boolean | AccountssArgs | null | undefined'.
#0 63.80     Type 'S["include"]["created_by_account"]' is not assignable to type 'boolean | AccountssArgs | null | undefined'.
#0 63.80       Type 'S["include"]["created_by_account"]' is not assignable to type 'AccountssArgs'.
#0 63.80         Type 'S["include"]["created_by_account"]' is not assignable to type 'AccountssArgs'.
#0 63.80           Type 'S["include"][P]' is not assignable to type 'AccountssArgs'.
#0 63.80             Type 'S["include"]["created_by_account"]' is not assignable to type 'AccountssArgs'.
#0 63.80               Type 'S["include"]["created_by_account"]' is not assignable to type 'AccountssArgs'.
#0 63.80
#0 63.80   10329 |     ? Accountss  & {
#0 63.80   10330 |     [P in TrueKeys<S['include']>]:
#0 63.80 > 10331 |         P extends 'created_by_account' ? AccountssGetPayload<S['include'][P]> :
#0 63.80         |                                                              ^
#0 63.80   10332 |         P extends 'modified_by_account' ? AccountssGetPayload<S['include'][P]> :
#0 63.80   10333 |         P extends 'account_is_personel' ? personel_employeesGetPayload<S['include'][P]> | null :
#0 63.80   10334 |         P extends 'students' ? studentsGetPayload<S['include'][P]> | null :
#0 63.93
#0 63.93 > Build error occurred

The "solution" mentioned in #9421 of renaming model fooUpdate when having another model foo in the schema did not resolve the error for me.

Environment & Setup

  • OS: Artix Linux
  • Database: MariaDB
  • Node.js version: v14.20.0
  • Typescript version: 4.8.2

Prisma Version

prisma                  : 3.10.0
@prisma/client          : 3.10.0
Current platform        : debian-openssl-1.1.x
Query Engine (Node-API) : libquery-engine 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node)
Migration Engine        : migration-engine-cli 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine    : introspection-core 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary           : prisma-fmt 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash    : 73e60b76d394f8d37d8ebd1f8918c79029f0db86
Studio                  : 0.458.0
Preview Features        : interactiveTransactions, filterJson

@CanTheAlmighty
Copy link

CanTheAlmighty commented Nov 24, 2022

I ran into the same issue today with Typescript 4.9 and Prisma 4.6.1 (In fact, I actually upgraded everything hoping it would fix itself).

The errors:

node_modules/.prisma/client/index.d.ts(25062,64): error TS2344: Type 'T' does not satisfy the constraint 'boolean | EventPostUpdateArgs | null | undefined'.
  Type 'EventPostUpdateFindUniqueArgsBase' is not assignable to type 'boolean | EventPostUpdateArgs | null | undefined'.
    Type 'EventPostUpdateFindUniqueArgsBase' is not assignable to type 'EventPostUpdateArgs'.
      Type 'T' is not assignable to type 'EventPostUpdateArgs'.

Renaming the models from FooUpdate to FooChanges fixed the issue instantly, but it required an insane amount of google-fu to reach this issue.

Edit

Taking a peek at the file generated, it would seem that the generated typescript file heavily relies on the word Update. For example, I have an object named Board, and these are the results of compilation:

...
export type BoardUpdateArgs = { ... }
...
export type BoardArgs = { ... }

So the problem exists when you have Object and ObjectUpdate as it will attempt to create as such:

Object
  -> ObjectArgs
  -> ObjectUpdateArgs**
ObjectUpdate
  -> ObjectUpdateArgs**
  -> ObjectUpdateUpdateArgs

@CanTheAlmighty
Copy link

I just found out today that it also happens when properties are also named update or updates, again, renamed "update" to "props" has circumvented the issue.

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
@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. topic: generator topic: reserved words See https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#naming-conventions topic: type-clash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants