prisma
prisma copied to clipboard
`DateTime` doesn't support ISO string with offset
Bug description
When passing ISO8601 strings with offset information, prisma throws an error.
How to reproduce
With a Prisma schema:
model Task {
startDate: DateTime @db.Timestampz
}
A Zulu ISO8601 string works:
prisma.task.create({
data: {
startDate: "2021-09-28T22:00Z"
}
})
A ISO8601 string doesn't
prisma.task.create({
data: {
startDate: "2021-09-29T00:00+02:00"
}
})
with the error:
Error: Argument startDate: Got invalid value '2021-09-29T00:00+02:00' on prisma.createTask. Provided String, expected DateTime or Null.
Expected behavior
No response
Prisma information
model Task {
startDate: DateTime @db.Timestampz
}
Environment & setup
- OS: mac os , m1 chip
- Database: PostgreSQL v13
- Node.js version: node 16
Prisma Version
v2.30.3
The issue is still reproducible with the latest Prisma version.
Schema:
generator client {
provider = "prisma-client-js"
output = "../node_modules/.prisma/client"
}
datasource db {
provider = "postgresql"
url = env("TEST_POSTGRES_URI")
}
model Task {
id Int @id @default(autoincrement())
startDate DateTime @db.Timestamptz
}
Code:
import { PrismaClient } from '.prisma/client'
async function main() {
const prisma = new PrismaClient()
const result = await prisma.task.create({
data: {
startDate: '2021-09-29T00:00+02:00',
},
})
console.log(result)
}
void main()
Result:
/Users/aqrln/prisma/prisma/reproductions/reproductions/gh-9516/node_modules/.prisma/client/runtime/index.js:28989
const error2 = new PrismaClientValidationError(renderErrorStr(validationCallsite));
^
PrismaClientValidationError:
Invalid `prisma.task.create()` invocation in
/Users/aqrln/prisma/prisma/reproductions/reproductions/gh-9516/index.ts:6:36
3 async function main() {
4 const prisma = new PrismaClient()
5
→ 6 const result = await prisma.task.create({
data: {
startDate: '2021-09-29T00:00+02:00'
~~~~~~~~~~~~~~~~~~~~~~~~
}
})
Argument startDate: Got invalid value '2021-09-29T00:00+02:00' on prisma.createOneTask. Provided String, expected DateTime.
at Document.validate (/Users/aqrln/prisma/prisma/reproductions/reproductions/gh-9516/node_modules/.prisma/client/runtime/index.js:28989:20)
at serializationFn (/Users/aqrln/prisma/prisma/reproductions/reproductions/gh-9516/node_modules/.prisma/client/runtime/index.js:31903:19)
at runInChildSpan (/Users/aqrln/prisma/prisma/reproductions/reproductions/gh-9516/node_modules/.prisma/client/runtime/index.js:25102:12)
at PrismaClient._executeRequest (/Users/aqrln/prisma/prisma/reproductions/reproductions/gh-9516/node_modules/.prisma/client/runtime/index.js:31910:31)
at async PrismaClient._request (/Users/aqrln/prisma/prisma/reproductions/reproductions/gh-9516/node_modules/.prisma/client/runtime/index.js:31839:16)
at async main (/Users/aqrln/prisma/prisma/reproductions/reproductions/gh-9516/index.ts:6:18) {
clientVersion: '0.0.0'
}
The regular expression that decides if a string is a valid date somewhere in query.ts
doesn't match an ISO string with offset, which needs to be fixed.
The workaround is to pass a Date instead of a string:
const result = await prisma.task.create({
data: {
- startDate: '2021-09-29T00:00+02:00',
+ startDate: new Date('2021-09-29T00:00+02:00'),
},
})
As of 2024 this issue is still here I want to store the simple date and currently passing the Iso format based string
DateFound DateTime @db.Date
DateFound DateTime
in both cases when I pass the string 1990-05-06
which's the standard iso date format I still the same error
nInvalid value for argument
DateFound: premature end of input. Expected ISO-8601 DateTime.
As of 2024 this issue is still here I want to store the simple date and currently passing the Iso format based string
DateFound DateTime @db.Date
DateFound DateTime
in both cases when I pass the string1990-05-06
which's the standard iso date format I still the same error
nInvalid value for argument
DateFound: premature end of input. Expected ISO-8601 DateTime.
Any news? I'm having the same issue 😞
Same issue here
Same issue here
I'm having the same issue as well.