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 target types only accept strings or numbers, found: {"latitude":null,"longitude":null} #20331

Closed
i-am-dev-Siddhesh opened this issue Jul 21, 2023 · 5 comments
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. tech/engines Issue for tech Engines. topic: broken query topic: Json Scalar type `Json`

Comments

@i-am-dev-Siddhesh
Copy link

i-am-dev-Siddhesh commented Jul 21, 2023

Hi Prisma Team! My Prisma Client just crashed. This is the report:

Versions

Name Version
Node v16.20.0
OS windows
Prisma Client 4.14.1
Query Engine d9a4c5988f480fa576d43970d5a23641aa77bc9c
Database postgresql

Logs

prisma:tryLoadEnv Environment variables loaded from E:\Mobile app\Bazaar\.env
prisma:client checkPlatformCaching:postinstall 
prisma:client checkPlatformCaching:ciName 
prisma:tryLoadEnv Environment variables loaded from E:\Mobile app\Bazaar\.env
prisma:client dirname E:\Mobile app\Bazaar\node_modules\.prisma\client
prisma:client relativePath ..\..\..\prisma
prisma:client cwd E:\Mobile app\Bazaar\prisma
prisma:client protocol graphql
prisma:client clientVersion 4.14.1
prisma:client clientEngineType library
prisma:client:libraryEngine internalSetup
prisma:client:libraryEngine:loader Searching for Query Engine Library in E:\Mobile app\Bazaar\node_modules\.prisma\client
prisma:client:libraryEngine:loader loadEngine using E:\Mobile app\Bazaar\node_modules\.prisma\client\query_engine-windows.dll.node
prisma:client:libraryEngine library starting
prisma:client:libraryEngine library started
prisma:client:libraryEngine sending request, this.libraryStarted: true

Client Snippet

export const fetchData= async (req: Request, res: Response) => {
  try {
    const items = await prisma.cattle.findMany({
      where: {
        location: {
          gte: {
            latitude: 12.34,
            longitude: 56.78,
          },
          lte: {
            latitude: 90.12,
            longitude: 180.34,
          },
        },
      },
    });

...reso logic
  } catch (error: any) {
    ...throw logic
  }
};

Schema

model test{
  id    Int     @id @default(autoincrement())

location Json
  createdAt  DateTime           @default(now())
  updatedAt  DateTime?          @updatedAt
} 

Prisma Engine Query

 const items = await prisma.test.findMany({
      where: {
        location: {
          gte: {
            latitude: 12.34,
            longitude: 56.78,
          },
          lte: {
            latitude: 90.12,
            longitude: 180.34,
          },
        },
      }
      ,
    });
@millsp millsp added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. tech/engines Issue for tech Engines. topic: Json Scalar type `Json` topic: broken query team/client Issue for team Client. labels Jul 21, 2023
@millsp
Copy link
Member

millsp commented Jul 21, 2023

Hey @i-am-dev-Siddhesh thanks for the report. Would you mind trying on the latest version? Thanks.

@millsp
Copy link
Member

millsp commented Jul 21, 2023

(Possibly related issue/domain in the past #10836)

@millsp millsp added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. and removed bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. labels Jul 21, 2023
@millsp
Copy link
Member

millsp commented Jul 21, 2023

Hey, I forwarded this internally, and my colleague suggested that you re-write your query as the following:

where: {
  AND: [
    { json: { path: ["latitude"], gte: 12.34 } },
    { json: { path: ["latitude"], lte: 90.12 } },
    { json: { path: ["longitude"], gte: 56.78 } },
    { json: { path: ["longitude"], lte: 180.34 } },
  ]
}

Because you are currently comparing two objects (json object >= json object), which might not be what you want.

@i-am-dev-Siddhesh
Copy link
Author

Hey @i-am-dev-Siddhesh thanks for the report. Would you mind trying on the latest version? Thanks.

Yes. I'm

@i-am-dev-Siddhesh
Copy link
Author

comparing two objects (json object >= json object), w

Anyways Currently I moved the lat and long from json to int in db which cause some changes in flow.
Thanks for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. tech/engines Issue for tech Engines. topic: broken query topic: Json Scalar type `Json`
Projects
None yet
Development

No branches or pull requests

2 participants