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

Where filter not working with JSON.not with another condition #6755

Closed
AnandChowdhary opened this issue Apr 23, 2021 · 2 comments
Closed

Where filter not working with JSON.not with another condition #6755

AnandChowdhary opened this issue Apr 23, 2021 · 2 comments
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: Json Scalar type `Json`
Milestone

Comments

@AnandChowdhary
Copy link

AnandChowdhary commented Apr 23, 2021

Bug description

Please see this repository for reproduction: https://github.com/AnandChowdhary/prisma-6755-reproduction

If you have a findMany with a JSON filter (using not) and another condition, the second condition is entirely ignored:

console.log(
  await prisma.user.findMany({ where: { AND: [{ data: { not: "example-string" } }, { id: 2 }] } })
);

In the above, I would expect that Prisma returns all users that don't have this JSON value in data and their ID is 2. Instead, Prisma just returns all users without this JSON value, completely ignoring the second condition.

Schema and code

datasource mysql {
  provider = "mysql"
  url      = env("DATABASE_URL")
}

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

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  data  Json?
}
// Create a user without JSON
await prisma.user.create({
  data: { id: 1, email: "hello-1@example.com", name: "First" },
});
// Create a user with JSON data
await prisma.user.create({
  data: {
    id: 2,
    email: "hello-2@example.com",
    name: "Second",
    data: { hello: "second" },
  },
});
// Create another user with JSON data
await prisma.user.create({
  data: {
    id: 3,
    email: "hello-3@example.com",
    name: "Third",
    data: { hello: "third" },
  },
});

console.log(
  "All users with JSON data and their ID is 2",
  await prisma.user.findMany({ where: { data: { not: "example-string" }, id: 2 } })
);
// SHOULD DO THIS: Logs an array of a single user with ID 2
// ACTUALLY DOES THIS: Logs an array of both users with ID 2 and 3

Environment & setup

  • OS: macOS
  • Database: MySQL
  • Node.js version: v14.16.0
  • Prisma version: 2.21.2
prisma               : 2.21.2
@prisma/client       : 2.21.2
Current platform     : darwin
Query Engine         : query-engine e421996c87d5f3c8f7eeadd502d4ad402c89464d (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine     : migration-engine-cli e421996c87d5f3c8f7eeadd502d4ad402c89464d (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core e421996c87d5f3c8f7eeadd502d4ad402c89464d (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary        : prisma-fmt e421996c87d5f3c8f7eeadd502d4ad402c89464d (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : e421996c87d5f3c8f7eeadd502d4ad402c89464d
Studio               : 0.371.0
@AnandChowdhary AnandChowdhary changed the title Where filter not working with JSON.not and another condition Where filter not working with JSON.not with another condition Apr 23, 2021
@pantharshit00
Copy link
Contributor

I can reproduce this. Thanks for detailed reproduction repository.

@pantharshit00 pantharshit00 added bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. process/candidate team/client Issue for team Client. topic: Json Scalar type `Json` labels Apr 30, 2021
@matthewmueller matthewmueller added this to the 2.23.0 milestone May 5, 2021
@Weakky
Copy link
Member

Weakky commented May 17, 2021

Hey @AnandChowdhary and @pantharshit00, I cannot reproduce this issue anymore on 2.22.1.

I'm closing now, please let me know if I missed something.

@Weakky Weakky closed this as completed May 17, 2021
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: Json Scalar type `Json`
Projects
None yet
Development

No branches or pull requests

4 participants