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.

The client fetches Scalar list fields as [] while they behave as if the value is NULL.

See original GitHub issue

Bug description

Item with scalar list field of value NULL comes as empty list from the prismaClient. This makes when consuming data, impossible to differentiate between empty lists and NULL value lists.

How to reproduce

Running:

const blogPost0 = await prismaClient.blogPost.create({});
const blogPost1 = await prismaClient.blogPost.create({ tags: [] });
console.log({ blogPost0, blogPost1 });

// Logs
// { 
//  blogPost0: {
//    "id": "3b7a0ff6-dbe5-450a-a10f-af9aa0f0adff",
//    "createdAt": "2022-06-16T15:23:19.856Z",
//    "tags": [],  // The item behaves as if the value is NULL, but is fetched as empty list.
//  },
//  blogPost1: {
//    "id": "248f05b8-590a-4342-af9b-651aa5831df0",
//    "createdAt": "2022-06-16T15:23:19.875Z",
//    "tags": [],
//  }
//}

const blogPostsWithoutTag = await prismaClient.blogPost.findMany({
  where: {
    tag: {
      isEmpty: true,
    },
  },
});
console.log(blogPostsWithoutTag);

// Logs
//  [{
//    "id": "248f05b8-590a-4342-af9b-651aa5831df0",
//    "createdAt": "2022-06-16T15:23:19.875Z",
//    "tags": [],
//  }]
// This proofs that the item 'blogPost0' behaves as if the value of the 'tag' field is 'NULL' and not an empty list.

Expected behavior

No response

Prisma information

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

generator client {
  provider = "prisma-client-js"
  output   = "../generated/client"
  previewFeatures = []
}

model BlogPost {
  id                   String               @id @default(uuid())
  createdAt            DateTime             @default(now())
  tags                 String[]
}

Environment & setup

  • OS: Mac OS
  • Database: PostgreSQL
  • Node.js version: v16.13.0

Prisma Version

3.15.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
matthewmuellercommented, Jun 17, 2022

Re-opening since since @lskuper indeed pointed out it’s a slightly different request.

It’s a consequence of not having nullable list support that we coerce to empty lists. This would likely be solved as part of #4729.

0reactions
matthewmuellercommented, Jun 21, 2022

Closing in favor of #13880

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reading and writing data to the cache - Apollo GraphQL Docs
If the cache is missing data for any of the query's fields, readQuery returns null . It does not attempt to fetch data...
Read more >
Why does a GraphQL query return null? - Stack Overflow
There's two common reasons your field or fields are resolving to null: 1) returning data in the wrong shape inside your resolver; ...
Read more >
Using the SQL Coalesce function in SQL Server - SQLShack
But, again, it's just a review to let you know what happens when we have a NULL value ... It allows handling the...
Read more >
Null Values - Azure Data Explorer | Microsoft Learn
The where operator uses Boolean expressions to determine if to emit each input record to the output. This operator treats null values as...
Read more >
GraphQL List - How to use arrays in GraphQL schema ...
A Non-Null modifier allows us to define if the type/field is required. ... List. In general, a GraphQL list represents a sequence of...
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