JSON fields filtering stopped working in 2.5.0
See original GitHub issueBug description
Filtering on JSON field (equals, not) stopped working in 2.5.0.
How to reproduce
Running this code:
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient({});
async function main() {
await prisma.$connect();
await prisma.post.deleteMany({});
await prisma.post.create({
data: {
title: "Post title 1",
metadata: {
published: true,
},
},
});
await prisma.post.create({
data: {
title: "Post title 2",
metadata: {
published: false,
},
},
});
await prisma.post.create({
data: {
title: "Post title 3",
metadata: {
otherKey: "otherValue",
},
},
});
const allPosts = await prisma.post.findMany();
const publishedPosts = await prisma.post.findMany({
where: {
metadata: {
equals: {
published: true,
},
},
},
});
const notPublishedPosts = await prisma.post.findMany({
where: {
metadata: {
equals: {
published: false,
},
},
},
});
const notEqualsPublishedPosts = await prisma.post.findMany({
where: {
metadata: {
not: {
equals: {
published: true,
},
},
},
},
});
console.log(
util.inspect(
{
allPosts,
publishedPosts,
notPublishedPosts,
notEqualsPublishedPosts,
},
false,
null
)
);
}
main()
.catch((e) => console.error(e))
.finally(async () => {
await prisma.$disconnect();
});
Results in this:
{
allPosts: [
{ id: 9, title: 'Post title 1', metadata: { published: true } },
{ id: 10, title: 'Post title 2', metadata: { published: false } },
{
id: 11,
title: 'Post title 3',
metadata: { otherKey: 'otherValue' }
}
],
publishedPosts: [],
notPublishedPosts: [],
notEqualsPublishedPosts: []
}
Expected behavior
It should return properly filtered data.
Prisma information
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model Post {
id Int @id @default(autoincrement())
title String
metadata Json
}
Environment & setup
- OS: Windows 10 (WSL2 Ubuntu 20.04)
- Database: Postgres
- Node.js version: 14
- Prisma version:
@prisma/cli : 2.5.0
Current platform : debian-openssl-1.1.x
Query Engine : query-engine 9a670138b1db276001d785a2adcba1584c869d24 (at node_modules/@prisma/cli/query-engine-debian-openssl-1.1.x)
Migration Engine : migration-engine-cli 9a670138b1db276001d785a2adcba1584c869d24 (at node_modules/@prisma/cli/migration-engine-debian-openssl-1.1.x)
Introspection Engine : introspection-core 9a670138b1db276001d785a2adcba1584c869d24 (at node_modules/@prisma/cli/introspection-engine-debian-openssl-1.1.x)
Format Binary : prisma-fmt 9a670138b1db276001d785a2adcba1584c869d24 (at node_modules/@prisma/cli/prisma-fmt-debian-openssl-1.1.x)
Studio : 0.259.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (7 by maintainers)
Top Results From Across the Web
Json filter not working on array while using jq - Stack Overflow
i have the following json format and trying to filter it using jq. My requirement is to print the "read-transactions" value. I. tried...
Read more >Working with JSON data in Google Standard SQL | BigQuery
This document describes how to create a table with a JSON column, insert JSON data into a BigQuery table, and query JSON data....
Read more >Handle json filter field name cannot be an empty string error
Two problems. Firstly, the json filter has to come before the ruby filter, otherwise the [msgParts] field does not exist when the ruby ......
Read more >Parsing JSON in command-line with jq: basic filters and ...
Introduction; Invoking jq; Processing input from command other than curl; Extracting fields from the array; Filtering null values with ...
Read more >2 Overview of SODA Filter Specifications (QBEs)
A filter specification is a pattern expressed in JSON. ... $nin — whether a field value is not a member of a given...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks a lot for reporting 🙏 This issue is fixed in the latest dev version of
@prisma/cli
. You can try it out withnpm i -g @prisma/cli@dev
.In case it’s not fixed for you - please let us know and we’ll reopen this issue!
Good point @MichalLytek ! I just created a separate issue for that: https://github.com/prisma/prisma/issues/3441