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

JSON number filtering bug #8224

Closed
Tracked by #8628
firmanjml opened this issue Jul 11, 2021 · 1 comment · Fixed by prisma/prisma-engines#2174
Closed
Tracked by #8628

JSON number filtering bug #8224

firmanjml opened this issue Jul 11, 2021 · 1 comment · Fixed by prisma/prisma-engines#2174
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: client api topic: filterJson topic: Json Scalar type `Json`
Milestone

Comments

@firmanjml
Copy link

firmanjml commented Jul 11, 2021

Bug description

Number JSON filtering is not working as it should be with large number that are far apart from each other for example 50, 100

prisma:query SELECT "public"."Test"."id", "public"."Test"."metadata" FROM "public"."Test" WHERE (("public"."Test"."metadata"#>>ARRAY[$1]::text[]) >= $2 AND JSONB_TYPEOF(("public"."Test"."metadata"#>ARRAY[$3]::text[])) = $4) 
OFFSET $5
TEST1 [
  {
    "id": 1,
    "metadata": {
      "price": 50
    }
  },
  {
    "metadata": {
      "price": 100
    }
  }
]

prisma:query SELECT "public"."Test"."id", "public"."Test"."metadata" FROM "public"."Test" WHERE (("public"."Test"."metadata"#>>ARRAY[$1]::text[]) >= $2 AND JSONB_TYPEOF(("public"."Test"."metadata"#>ARRAY[$3]::text[])) = $4) 
OFFSET $5
TEST2 [
  {
    "id": 1,
    "metadata": {
      "price": 50
    }
  }
]

How to reproduce

  1. copy paste the schema and index.ts code
  2. npx prisma migrate dev --name init
  3. ts-node index.ts
  4. spot the bug

Expected behavior

Database Data
image

Two rows will be return if price is greater than or equal 50 instead of getting 1 row in TEST2 from console log.

Prisma information

Schema

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

generator client {
  provider = "prisma-client-js"
  previewFeatures = ["filterJson"]
}

model Test {
  id       Int  @id @default(autoincrement())
  metadata Json
}

index.ts

import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient({
    log: ["query"]
})

async function main() {
    const data1 = await prisma.test.findMany({
        where: {
            metadata: {
                path: ['price'],
                gte: 1
            }
        }
    });

    console.log("TEST1", JSON.stringify(data1, null, 2));

    const data2 = await prisma.test.findMany({
        where: {
            metadata: {
                path: ['price'],
                gte: 50
            }
        }
    });

    console.log("TEST2", JSON.stringify(data2, null, 2));

}

main()
    .catch((e) => {
        throw e
    })
    .finally(async () => {
        await prisma.$disconnect()
    })

Environment & setup

  • OS: Windows
  • Database: PostgresSQL
  • Node.js version: v16.4.2

Prisma Version

prisma               : 2.26.0
@prisma/client       : 2.26.0
Current platform     : windows
Query Engine         : query-engine 9b816b3aa13cc270074f172f30d6eda8a8ce867d (at node_modules\@prisma\engines\query-engine-windows.exe)
Migration Engine     : migration-engine-cli 9b816b3aa13cc270074f172f30d6eda8a8ce867d (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine : introspection-core 9b816b3aa13cc270074f172f30d6eda8a8ce867d (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary        : prisma-fmt 9b816b3aa13cc270074f172f30d6eda8a8ce867d (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash : 9b816b3aa13cc270074f172f30d6eda8a8ce867d
Studio               : 0.408.0
Preview Features     : filterJson
@firmanjml firmanjml added the kind/bug A reported bug. label Jul 11, 2021
@janpio janpio added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. team/client Issue for team Client. topic: client api topic: filterJson topic: Json Scalar type `Json` labels Jul 11, 2021
@pantharshit00
Copy link
Contributor

I can reproduce this with 2.27.0-dev.59. Thanks for the detailed report.

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: client api topic: filterJson topic: Json Scalar type `Json`
Projects
None yet
5 participants