Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🐛 Normalize empty string time zones to null (#2543)

Luke Vella9abdfba50dab
diff --git a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-options/page.tsx b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-options/page.tsx
index 5e32c768c..2a69d39f3 100644
--- a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-options/page.tsx
+++ b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-options/page.tsx
@@ -109,7 +109,7 @@ const Page = () => {
updatePollMutation(
{
pollId: poll.id,
- timeZone: data.timeZone,
+ timeZone: data.timeZone || null,
optionsToDelete: optionsToDelete.map(({ id }) => id),
optionsToAdd,
},
diff --git a/apps/web/src/components/create-poll.tsx b/apps/web/src/components/create-poll.tsx
index a993c3ba6..8703de01a 100644
--- a/apps/web/src/components/create-poll.tsx
+++ b/apps/web/src/components/create-poll.tsx
@@ -94,7 +94,7 @@ export const CreatePoll: React.FunctionComponent = () => {
title: title,
location: formData?.location?.trim(),
description: formData?.description?.trim(),
- timeZone: formData?.timeZone,
+ timeZone: formData?.timeZone || null,
hideParticipants: formData?.hideParticipants,
disableComments: formData?.disableComments,
hideScores: formData?.hideScores,
diff --git a/apps/web/src/trpc/routers/polls.ts b/apps/web/src/trpc/routers/polls.ts
index bc729ee40..4ec213526 100644
--- a/apps/web/src/trpc/routers/polls.ts
+++ b/apps/web/src/trpc/routers/polls.ts
@@ -30,6 +30,7 @@ import {
} from "../trpc";
import { comments } from "./polls/comments";
import { participants } from "./polls/participants";
+import { timeZoneInput } from "./polls/schema";
const collapseNewlines = (s: string) => s.replace(/\n{3,}/g, "\n\n");
@@ -98,7 +99,7 @@ export const polls = router({
.input(
z.object({
title: z.string().trim().min(1),
- timeZone: z.string().optional(),
+ timeZone: timeZoneInput,
location: z.string().trim().optional(),
description: z.string().trim().transform(collapseNewlines).optional(),
hideParticipants: z.boolean().optional(),
@@ -288,7 +289,7 @@ export const polls = router({
z.object({
pollId: z.string(),
title: z.string().trim().optional(),
- timeZone: z.string().optional(),
+ timeZone: timeZoneInput,
location: z.string().trim().optional(),
description: z.string().trim().transform(collapseNewlines).optional(),
optionsToDelete: z.string().array().optional(),
diff --git a/apps/web/src/trpc/routers/polls/schema.test.ts b/apps/web/src/trpc/routers/polls/schema.test.ts
new file mode 100644
index 000000000..fe13611ed
--- /dev/null
+++ b/apps/web/src/trpc/routers/polls/schema.test.ts
@@ -0,0 +1,20 @@
+import { describe, expect, it } from "vitest";
+import { timeZoneInput } from "./schema";
+
+describe("timeZoneInput", () => {
+ it("normalizes an empty string to null", () => {
+ expect(timeZoneInput.parse("")).toBeNull();
+ });
+
+ it("passes a timezone through unchanged", () => {
+ expect(timeZoneInput.parse("Europe/Berlin")).toBe("Europe/Berlin");
+ });
+
+ it("keeps undefined as undefined so modify can mean 'leave unchanged'", () => {
+ expect(timeZoneInput.parse(undefined)).toBeUndefined();
+ });
+
+ it("keeps null as null", () => {
+ expect(timeZoneInput.parse(null)).toBeNull();
+ });
+});
diff --git a/apps/web/src/trpc/routers/polls/schema.ts b/apps/web/src/trpc/routers/polls/schema.ts
new file mode 100644
index 000000000..88c82d168
--- /dev/null
+++ b/apps/web/src/trpc/routers/polls/schema.ts
@@ -0,0 +1,10 @@
+import * as z from "zod";
+
+// A falsy poll timeZone means "floating". Clients historically sent "" for
+// floating time polls; normalize it to null at the boundary so it can never
+// be persisted. undefined must pass through untouched: in `modify` it means
+// "leave the current value unchanged".
+export const timeZoneInput = z
+ .string()
+ .transform((value) => value || null)
+ .nullish();
diff --git a/packages/database/prisma/migrations/20260708131500_normalize_empty_string_time_zones/migration.sql b/packages/database/prisma/migrations/20260708131500_normalize_empty_string_time_zones/migration.sql
new file mode 100644
index 000000000..b3ddf1b81
--- /dev/null
+++ b/packages/database/prisma/migrations/20260708131500_normalize_empty_string_time_zones/migration.sql
@@ -0,0 +1,10 @@
+-- A falsy time zone means "floating" in app code, but '' is NOT NULL in SQL:
+-- AT TIME ZONE '' errors and '' rows would fail the CHECK constraints planned
+-- in RAL-1257. Normalize every time zone column so past rows match the
+-- normalized writes.
+UPDATE polls SET time_zone = NULL WHERE time_zone = '';
+UPDATE scheduled_events SET time_zone = NULL WHERE time_zone = '';
+UPDATE participants SET time_zone = NULL WHERE time_zone = '';
+UPDATE scheduled_event_invites SET invitee_time_zone = NULL WHERE invitee_time_zone = '';
+UPDATE users SET time_zone = NULL WHERE time_zone = '';
+UPDATE provider_calendars SET time_zone = NULL WHERE time_zone = '';