-
Notifications
You must be signed in to change notification settings - Fork 9.3k
fix: Host schedule not updating upon updating/deleting default schedule #20750
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
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 2 Skipped Deployments
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mrge found 1 issue across 3 files. View it in mrge.io
Graphite Automations"Add consumer team as reviewer" took an action on this PR • (04/17/25)1 reviewer was added to this PR based on Keith Williams's automation. |
} else { | ||
if (user.defaultScheduleId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else if
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good other than the nit I left
Keith wanted us to write unit tests for each server function we write, can you do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mrge found 2 issues across 3 files. View them in mrge.io
@@ -45,6 +46,8 @@ export const deleteHandler = async ({ input, ctx }: DeleteOptions) => { | |||
// to throw the error if there arent any other schedules | |||
if (!scheduleToSetAsDefault) throw new TRPCError({ code: "BAD_REQUEST" }); | |||
|
|||
await updateHostsWithNewDefaultSchedule(user.id, input.scheduleId, scheduleToSetAsDefault.id, prisma); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing error handling around this async operation could lead to inconsistent state if it fails
@@ -45,6 +46,8 @@ | |||
// to throw the error if there arent any other schedules | |||
if (!scheduleToSetAsDefault) throw new TRPCError({ code: "BAD_REQUEST" }); | |||
|
|||
await updateHostsWithNewDefaultSchedule(user.id, input.scheduleId, scheduleToSetAsDefault.id, prisma); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a database transaction for related database operations to ensure atomicity
scheduleId: number, | ||
prisma: PrismaClient | ||
) => { | ||
return prisma.host.updateMany({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to use prisma
directly in trpc
routers
We should create a repository function and use that here
Pull request was converted to draft
E2E results are ready! |
Summary by mrge
Fixed host schedule synchronization to properly update when default schedules are changed, deleted, or updated.
Bug Fixes
setupHostDefaultSchedule
function to ensure host schedules stay in sync with user default schedules