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.

Error: Provided String, expected DateTime or DateTimeFieldUpdateOperationsInput

See original GitHub issue

I’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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
maoosicommented, Dec 4, 2020

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:

  • Using .toISOString() is working as expected.
  • Using new Date() is working as expected.
  • Using the ISO 8601 DateTime format returned by the date-fns/formatISO method isn’t working.
  • Using the ISO 8601 DateTime format returned by the AWSDateTime scalar type isn’t working.

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() or new 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()?

4reactions
pantharshit00commented, Dec 24, 2020

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 to timestamp(3) in the database which has millisecond precision in match and storing. If you just want to filter, use the Date native type like so(native types are in preview):

model Event {
  id              String   @id @default(uuid())
  date            DateTime @db.Date
  isOccuringFirst Boolean
  startTime       String
  endTime         String
}

image

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:

import { PrismaClient } from "@prisma/client";
import { formatRFC3339 } from "date-fns";

async function main() {
  const prisma = new PrismaClient();
  const _dates = await prisma.event.findMany({
    where: {
      date: formatRFC3339(new Date()),
    },
  });

  console.log(_dates);

  prisma.$disconnect();
}

main();
Read more comments on GitHub >

github_iconTop 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 >

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