question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prisma WhereUniqueInput typings within node_modules are incorrect/broken

See original GitHub issue

Bug description

Prisma’s typings in node modules for the update function (UserScoresWhereUniqueInput) are wrong. It isn’t including everything from my schema, only the id. I have attempted to reinstall prisma, completely remove the node_modules, and run npx prisma generate again, but none of them succeeded in updating the typings correctly. The schema in the database looks correct, just not in the typings.

How to reproduce

Generate a prisma schema, put something similar to

model UserScores {
	id           Int    @id @default(autoincrement())
    guildId      String
    userId       String
    globalPoints Int
    weeklyPoints Int
}

in it, and try npx prisma generate. The d.ts file in .prisma where it says UserScoresWhereUniqueInput should only include the id.

Expected behavior

I expect UserScoresWhereUniqueInput to contain the rest of the things on the model, like guildId and userId.

Prisma information

Full schema:

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

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

model settings {
    id      Int     @id @default(autoincrement())
    guildId String
    prefix  String
}

model userScores {
    id           Int    @id @default(autoincrement())
    guildId      String
    userId       String
    globalPoints Int
    weeklyPoints Int
}

Database query that is erroring (typescript)

            await prisma.userScores.update({
                where: {
                    userId: message.author.id,
                    guildId: message.guild!.id,
                },
                data: {
                    globalPoints: 0,
                },
            });

Environment & setup

  • OS: Windows 10
  • Database: Postgresql
  • Node.js version: v14.16.0
  • Prisma version:
prisma               : 2.22.0
@prisma/client       : 2.22.0
Current platform     : windows
Query Engine         : query-engine 60cc71d884972ab4e897f0277c4b84383dddaf6c (at node_modules\@prisma\engines\query-engine-windows.exe)
Migration Engine     : migration-engine-cli 60cc71d884972ab4e897f0277c4b84383dddaf6c (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine : introspection-core 60cc71d884972ab4e897f0277c4b84383dddaf6c (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary        : prisma-fmt 60cc71d884972ab4e897f0277c4b84383dddaf6c (at node_modules\@prisma\engines\prisma-fmt-windows.exe)  
Default Engines Hash : 60cc71d884972ab4e897f0277c4b84383dddaf6c
Studio               : 0.379.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
janpiocommented, Sep 14, 2021

If you do not have a unique guarantee on the field you want to filter for, you need to use deleteMany or updateMany and it should let you filter as you are trying to.

3reactions
LabLambcommented, Jan 26, 2022

@janpio

Any suggestions how we could make that clearer or surface it at the right time?

I have colleagues that asked me the same question. I think it is perfectly fine to use updateMany if we dont use uniqueWhere, one DX improve can be adding a suggestion/tip saying:

Do you mean updateMany?

Read more comments on GitHub >

github_iconTop Results From Across the Web

prisma argument of type whereuniqueinput needs at least one ...
But I have a hard time with where selector in Prisma. ... prisma/prismaPrisma WhereUniqueInput typings within node_modules are incorrect/broken#6953.
Read more >
Advanced type safety (Reference) - Prisma
Prisma Client provides full type safety for queries, even for partial queries or included relations. This page explains how to leverage the generated...
Read more >
Nest js + prisma project, error in findUnique method in services
I tried locally and typing email as string works with findUnique without error. Can you please update your question to include how you...
Read more >
Prisma | NestJS - A progressive Node.js framework
Note The prisma generate command reads your Prisma schema and updates the generated Prisma Client library inside node_modules/@prisma/client . Use Prisma Client ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found