When try parse schemas with fields "DateTime" strings like: "YYYY-MM-DD" or "2023-01-10T00:00:00.000Z" throw this exception Expected date, received string.
Works if update generated files with z.coerce.date()
model HostMetric {
metric_at DateTime @id @unique @default(now())
host Host @relation(fields: [host_id], references: [id])
host_id Int
version String
mem_used Int /// Megabytes
mem_total Int /// Megabytes
cpu_used Int /// Percentage
cpu_total Int? /// Percentage
disk_used Int? /// Megabytes
disk_total Int? /// Megabytes
process_count Int
@@map("host_metrics")
}
Try parse using fastify
import { HostMetricUncheckedCreateInputObjectSchema } from "../../node_modules/.prisma/zod/client";
let worker = HostMetricUncheckedCreateInputObjectSchema.parse(body);
the response error
"Expected date, received string" on field metric_at
Bug description
When try parse schemas with fields "DateTime" strings like: "YYYY-MM-DD" or "2023-01-10T00:00:00.000Z" throw this exception Expected date, received string.
Works if update generated files with z.coerce.date()
How to reproduce
Create a model like this:
generator zod { provider = "prisma-zod-generator" output = "../../node_modules/.prisma/zod/client" isGenerateSelect = true isGenerateInclude = true }
model HostMetric { metric_at DateTime @id @unique @default(now()) host Host @relation(fields: [host_id], references: [id]) host_id Int version String mem_used Int /// Megabytes mem_total Int /// Megabytes cpu_used Int /// Percentage cpu_total Int? /// Percentage disk_used Int? /// Megabytes disk_total Int? /// Megabytes process_count Int
@@map("host_metrics") }
Try parse using fastify import { HostMetricUncheckedCreateInputObjectSchema } from "../../node_modules/.prisma/zod/client"; let worker = HostMetricUncheckedCreateInputObjectSchema.parse(body);
the response error "Expected date, received string" on field metric_at
Expected behavior
When send this body expected a new line inserted
{ "metric_at": "2023-01-10T00:00:00.000Z", "host_id": 1, "version": "1.23", "mem_used": 2000, "mem_total": 8000, "cpu_used": 1500, "cpu_total": 4000, "disk_used": 33000, "disk_total": 100000, "process_count": 1 }
Prisma information
Model:
generator zod { provider = "prisma-zod-generator" output = "../../node_modules/.prisma/zod/client" isGenerateSelect = true isGenerateInclude = true }
model HostMetric { metric_at DateTime @id @unique @default(now()) host Host @relation(fields: [host_id], references: [id]) host_id Int version String mem_used Int /// Megabytes mem_total Int /// Megabytes cpu_used Int /// Percentage cpu_total Int? /// Percentage disk_used Int? /// Megabytes disk_total Int? /// Megabytes process_count Int
@@map("host_metrics") }
Environment & setup
Prisma Version