Error: Provided String, expected DateTime or DateTimeFieldUpdateOperationsInput
See original GitHub issueI’m not entirely sure if this is a bug! If not a bug, then I’m a bit confused with the DateTime type…
Using Prisma 2.11.0 (with MySQL), I’ve created a new DateTime field in my schema.prisma
file as following:
model Story {
lastSavedAt DateTime @default(now())
}
When trying to update this particular field with the value 2020-11-23T17:41:59+11:00
I’m getting back the following error:
Argument lastSavedAt: Got invalid value '2020-11-23T17:41:59+11:00' on prisma.updateOneStory. Provided String, expected DateTime or DateTimeFieldUpdateOperationsInput:
type DateTimeFieldUpdateOperationsInput {
set?: DateTime
}
type DateTimeFieldUpdateOperationsInput {
set?: DateTime
}
The error outlines that I can’t use a String, while the TypeScript type returned for lastSavedAt
is:
// From VSCode
lastSavedAt?: string | Date | DateTimeFieldUpdateOperationsInput
// In the node_modules/.prisma/client/index.d.ts file
export type StoryUpdateInput = {
lastSavedAt?: XOR<Date | string, DateTimeFieldUpdateOperationsInput>
}
Am I missing something?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:13 (4 by maintainers)
Top Results From Across the Web
How to add time attribute in Prisma? - Stack Overflow
This is the error: Argument duration: Got invalid value '00:01:29' on prisma.createOneplaylist. Provided String, expected DateTime or Null.
Read more >prisma datetime null | The AI Search Engine You Control
I got this error: Argument deletedAt: Got invalid value null on prisma.findUniqueUser. Provided null, expected DateTime. In my model I explicitly say that ......
Read more >@prisma/cli: Versions | Openbase
Unclear Introspection error message: Error parsing attribute "@id": Fields that ... Provided String, expected DateTime or DateTimeFieldUpdateOperationsInput ...
Read more >Prisma 2.15.0 Release - GitClear
Please provide feedback for the new prisma db seed command here. ... Integer createdAt DateTime @default(now()) name String? email String?
Read more >Prisma+DateTime+DateFns - CodeSandbox
Prisma+DateTime+DateFns. 0. Embed Fork Create Sandbox Sign in. Sandbox Info. Prisma+DateTime+DateFns. 0. 90. 0. maoosimaoosi. TemplateNode HTTP Server ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for jumping on this @pantharshit00. Just to be clear, in my example above I was already using an ISO 8601 DateTime format - though allow me to expand a bit more around the issue.
I’ve been running a few different tests since my last message and here is what I’ve found:
.toISOString()
is working as expected.new Date()
is working as expected.Here’s a sandbox showing the issue using date-fns/formatISO (open terminal > yarn run test): https://codesandbox.io/s/prismadatetimedatefns-l7i2u?file=/index.ts
For my use case, I’m using Prisma inside a Lambda function, in combination with AWS AppSync. Therefore, my DateTime inputs are coming through as AWSDateTime scalar type (ISO 8601). In that context, you will understand that using
.toISOString()
ornew Date()
isn’t easily applicable. Ideally, Prisma would accept the ISO 8601 returned by AWS AppSync.Happy to be proven wrong, but I feel like Prisma isn’t supporting the ISO 8601 format entirely. But only in the exact shape returned by
.toISOString()
?Sorry for the late reply here.
@navicstein
If you want to filter via dates, you will need to use the date native type. By default
DateTime
maps totimestamp(3)
in the database which has millisecond precision in match and storing. If you just want to filter, use theDate
native type like so(native types are in preview):Now regarding your issue @maoosi. I can confirm that as a bug in our JS validator for dates.
Here is our date handling code: https://github.com/prisma/prisma-engines/blob/9a901beeaa4d52b23483c02dc9803aadb56f0e28/libs/prisma-value/src/lib.rs#L208 . This looks alright but the JS code doesn’t seem to have a proper validator. I think our regular expression is wrong here: https://github.com/prisma/prisma/blob/557aaaddae6c826c0b01fa282d0a28df2fa1011d/src/packages/client/src/runtime/utils/common.ts#L195
Reproduction: