zenstack icon indicating copy to clipboard operation
zenstack copied to clipboard

[Bug] Json filtering not working with `null` values

Open baenio opened this issue 2 months ago • 1 comments

Description and expected behavior It seems that there are some issues filtering Json fields with Prisma.DbNull, Prisma.JsonNull & Prisma.AnyNull. While Prisma detects it correctly, neither the hooks nor fetching directly from the ZenStack API find those records.

Screenshots Here are some data samples for the jsonb field:

  • (NULL) -> Prisma.DbNull
  • null -> Prisma.JsonNull
Image

Environment (please complete the following information):

  • ZenStack version: 2.19.2 & 2.20.1
  • Prisma version: 6.16.3
  • Database type: Postgresql
import { Prisma } from "@zenstackhq/runtime/models";

const { data } = useFindManyProperty({
  where: { geometry: { equals: Prisma.DbNull } }, // -> data.length returns 0
});
const { data } = useFindManyProperty({
  where: { geometry: { equals: Prisma.JsonNull } }, // -> data.length returns 0
});
const { data } = useFindManyProperty({
  where: { geometry: { equals: Prisma.AnyNull } }, // -> data.length returns 0
});
const { data } = useFindManyProperty({
  where: { geometry: { equals: null } }, // -> data.length returns 0
});

const data = await prisma.property.findMany({
  where: { geometry: { equals: Prisma.DbNull } }, // data.length returns 1
});
const data = await prisma.property.findMany({
  where: { geometry: { equals: Prisma.JsonNull } }, // data.length returns 2
});
const data = await prisma.property.findMany({
  where: { geometry: { equals: Prisma.AnyNull } }, // data.length returns 3
});
const data = await prisma.property.findMany({
  where: { geometry: { equals: null } }, // data.length returns 2 (same as JsonNull)
});

baenio avatar Oct 23 '25 16:10 baenio

Hi @baenio , thanks for filing this. I think the problem here is that Prisma.JsonNull and Prisma.DbNull are serialized across the network boundary and lose their identity during deserialization. Also importing values (types are completely fine) from "@zenstackhq/runtime/models" in frontend code is a bit risky, as it reexports from Prisma and may expose backend-only code.

We need to devise a way to support JSON null filtering with the hooks.

ymc9 avatar Oct 28 '25 22:10 ymc9