Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Date with a .toISOString() causes an error in the typeHint with PostgreSQL #2364

Open
colindeclue opened this issue May 22, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@colindeclue
Copy link

colindeclue commented May 22, 2024

What version of drizzle-orm are you using?

0.30.10

What version of drizzle-kit are you using?

0.21.4

Describe the Bug

I'm trying to update a workout with the Date objects startTime and endTime. When I just pass in the dates as they are, they are parsed as a timestamp without the timezone (which is not what my schema needs). When I pass them in as toISOString() as below, it throws a 500 error and parses it as a UUID.

export const tblWorkouts = pgTable("tblWorkouts", {
  workoutId: uuid("workoutId").primaryKey().notNull(),
  workoutName: text("workoutName").notNull(),
  organizationId: uuid("organizationId")
    .notNull()
    .references(() => tblOrganizations.organizationId),
  createdAt: timestamp("createdAt", { withTimezone: true }).notNull(),
  updatedAt: timestamp("updatedAt", { withTimezone: true }).notNull(),
  deletedAt: timestamp("deletedAt", { withTimezone: true }),
  startTime: timestamp("startTime", {
    withTimezone: true,
    mode: "string",
  }).notNull(),
  endTime: timestamp("endTime", {
    withTimezone: true,
    mode: "string",
  }).notNull(),
});
const workoutArray = await db
      .update(tblWorkouts)
      .set({
        workoutName,
        startTime: sql`${startTime.toISOString()}::timestamptz`,
        endTime: sql`${endTime.toISOString()}::timestamptz`,
      })
      .where(
        and(
          eq(tblWorkouts.organizationId, organizationId),
          eq(tblWorkouts.workoutId, workoutId),
        ),
      )
      .returning({
        workoutId: tblWorkouts.workoutId,
        organizationId: tblWorkouts.organizationId,
        workoutName: tblWorkouts.workoutName,
        startTime: tblWorkouts.startTime,
        endTime: tblWorkouts.endTime,
      });
Workout before save 2024-04-12T17:00:00.000Z 2024-04-13T03:00:00.000Z
Query: update "tblWorkouts" set "workoutName" = :1, "startTime" = :2::timestamptz, "endTime" = :3::timestamptz where ("tblWorkouts"."organizationId" = :4 and "tblWorkouts"."workoutId" = :5) returning "workoutId", "organizationId", "workoutName", "startTime", "endTime" -- params: [{"name":"1","value":{"stringValue":"Random Workout 270"}}, {"name":"2","value":{"stringValue":"2024-04-12T17:00:00.000Z"},"typeHint":"UUID"}, {"name":"3","value":{"stringValue":"2024-04-13T03:00:00.000Z"},"typeHint":"UUID"}, {"name":"4","value":{"stringValue":"09f500b2-14d0-43fa-aaa7-3872935e40ed"}}, {"name":"5","value":{"stringValue":"f4edfbde-2193-4028-971e-b3e3d661aa3e"}}]
500: UnknownError

Expected behavior

I'd expect either mode for the timestamp to work correctly, as in, the timezone should be part of the value portion of the update query on its own, and that it shouldn't parse it as a UUID when it's got the timezone at the correct place.

Environment & setup

Locally with my local data api layer.

@colindeclue colindeclue added the bug Something isn't working label May 22, 2024
@colindeclue
Copy link
Author

I've since discovered that timezones aren't supported in AWS Serverless v2, so I had to roll back my timestamps with timezone, but the bug still exists. Perhaps it should throw an error if you try to communicate with timezones, rather than cast it as a UUID.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant