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.

Falsy values cause validation exception

See original GitHub issue

Bug description

When the where clause contains falsy data the prisma validation blocks the query from running even when the query/data is valid.

Error: Cannot create Prisma Client where unique input because the source data ({ meeti
ngId: 1234, userId: 0 }) is missing the following unique identifier fields: userId

How to reproduce

      prisma.meetingStaff.findUnique({
        where: {
          meetingId_userId: {
            meetingId: 1234,
            userId: 0,
          }
        }
      })

Expected behavior

0 is a valid value, query should be executed

Prisma information

model Meeting {
  id                         Int                         @id @default(autoincrement())
  title                      String?
  meetingStaff               MeetingStaff[]

  @@map("meeting")
}

model MeetingStaff {
  meetingId Int     @map("meeting")
  userId    Int     @map("usernr")
  meeting   Meeting @relation(fields: [meetingId], references: [id], onDelete: Cascade)
  user      User    @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@id([meetingId, userId])
  @@map("meeting_staff")
}

model User {
  id                          Int                          @id @default(autoincrement())
  firstName                   String?                      @map("firstname")
  lastName                    String?                      @map("surname")
  meetingStaff                MeetingStaff[]

  @@map("users")
}

Environment & setup

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

Prisma Version

prisma                  : 4.0.0
@prisma/client          : 4.0.0
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine da41d2bb3406da22087b849f0e911199ba4fbf11 (at node_modules/.pnpm/@prisma+engines@3.16.0-49.da41d2bb3406da22087b849f0e911199ba4fbf11/node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli da41d2bb3406da22087b849f0e911199ba4fbf11 (at node_modules/.pnpm/@prisma+engines@3.16.0-49.da41d2bb3406da22087b849f0e911199ba4fbf11/node_modules/@prisma/engines/migration-engine-darwin-arm64)
Introspection Engine    : introspection-core da41d2bb3406da22087b849f0e911199ba4fbf11 (at node_modules/.pnpm/@prisma+engines@3.16.0-49.da41d2bb3406da22087b849f0e911199ba4fbf11/node_modules/@prisma/engines/introspection-engine-darwin-arm64)
Format Binary           : prisma-fmt da41d2bb3406da22087b849f0e911199ba4fbf11 (at node_modules/.pnpm/@prisma+engines@3.16.0-49.da41d2bb3406da22087b849f0e911199ba4fbf11/node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
Default Engines Hash    : da41d2bb3406da22087b849f0e911199ba4fbf11
Studio                  : 0.465.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
janpiocommented, Aug 9, 2022

@garth This is how my GitHub is displaying your error message: image Can you maybe retype meetingId in your Prisma Client Query to make sure there are not invisible characters in between that could problems? Then everything should just work.

0reactions
garthcommented, Aug 9, 2022

Thanks everyone for looking into this. We are working with 20+ year old data, so we sometimes find some odd behaviours, particularly when working with ts/js. We also had problems with other 3rd party libs that use if (row.id) {} or similar logic and submitted a few PRs here and there. But in the end we decided the best option would be to “fix” the data and we added migrations to update all primary keys that are not truthy values.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Validation - Throw Exception or Return False? - Jenkov.com
In this example the validate() method throws an exception as soon as an validation error is found. The insertAddress method cannot interact with ......
Read more >
Validation Error: Value is not valid - jsf - Stack Overflow
This error boils down to that the selected item does not match any of the available select item values specified by any nested...
Read more >
Truthy and Falsy Values: When All is Not Equal in JavaScript
Anything in JavaScript can be considered truthy or falsy. Learn what these values are and the rules that apply when they're compared.
Read more >
Falsy Values in JavaScript - freeCodeCamp
A falsy value is something which evaluates to FALSE, for instance when checking a variable. There are only six falsey values in JavaScript: ......
Read more >
Common validation errors when creating issue forms
You may see some of these common validation errors when creating, saving, or viewing issue forms. ... Body[i]: required attribute key value is...
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