question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSON fields filtering stopped working in 2.5.0

See original GitHub issue

Bug 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:closed
  • Created 3 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
timsuchanekcommented, Aug 25, 2020

Thanks a lot for reporting 🙏 This issue is fixed in the latest dev version of @prisma/cli. You can try it out with npm i -g @prisma/cli@dev.

In case it’s not fixed for you - please let us know and we’ll reopen this issue!

2reactions
timsuchanekcommented, Aug 26, 2020

Good point @MichalLytek ! I just created a separate issue for that: https://github.com/prisma/prisma/issues/3441

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found