Skip to content

findFirst with undefined value shouldn't return data #5149

@divyenduz

Description

@divyenduz

Bug description

Calling findFirst with an undefined in where filter still returns data. This is not intuitive.

How to reproduce

  1. Deploy this schema with yarn prisma db push --preview-feature
datasource ds {
    provider = "sqlite"
    url      = "file:./dev.db"
}

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

model User {
    id   String @id
    name String
}
  1. Ensure it has some rows
  2. Run the following script
const { PrismaClient } = require('@prisma/client')

const prisma = new PrismaClient()
async function main() {
  const data = await prisma.user.findFirst({
    where: {
      id: null
    },
  })
  console.log({ data })
}

main()
  1. It returns
{ data: { id: '1', name: 'Alice' } }
  1. The where ID doesn't match anything, it shouldn't return

Expected behaviour

IMO, this should be a runtime error.

Prisma information

(base) divyendusingh [p2-ff]$ yarn prisma --version                                                                                                                                  130 ↵
yarn run v1.22.4
$ /Users/divyendusingh/Documents/prisma/triage/p2-ff/node_modules/.bin/prisma --version
@prisma/cli          : 2.15.0-dev.57
@prisma/client       : 2.15.0-dev.57
Current platform     : darwin
Query Engine         : query-engine 6cece221de1da7dd83b9a158db5147e36f802cb1 (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine     : migration-engine-cli 6cece221de1da7dd83b9a158db5147e36f802cb1 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 6cece221de1da7dd83b9a158db5147e36f802cb1 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary        : prisma-fmt 6cece221de1da7dd83b9a158db5147e36f802cb1 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Studio               : 0.333.0

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions