:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(workflows): keep other schedules when saving an edited one (#126448)
Meikel Ratz2dab5450b3f0
diff --git a/products/workflows/frontend/Workflows/workflowLogic.autosave.test.ts b/products/workflows/frontend/Workflows/workflowLogic.autosave.test.tsindex 54580a686406..c2f86dff159c 100644--- a/products/workflows/frontend/Workflows/workflowLogic.autosave.test.ts+++ b/products/workflows/frontend/Workflows/workflowLogic.autosave.test.ts@@ -192,6 +192,32 @@ describe('workflowLogic auto-save', () => {expect(logic.values.currentSchedule?.id).toBe('schedule-created')})+ it('keeps the other schedules when a manual save writes the edited one', async () => {+ useMocks({+ patch: {+ '/api/environments/:team_id/hog_flows/:id/schedules/:schedule_id/': (req: any) => [+ 200,+ { id: req.params.schedule_id, rrule: 'FREQ=DAILY', starts_at: STARTS_AT, timezone: 'UTC' },+ ],+ },+ })+ const first: HogFlowSchedule = { id: 'schedule-1', rrule: 'FREQ=WEEKLY', starts_at: STARTS_AT }+ const second: HogFlowSchedule = { id: 'schedule-2', rrule: 'FREQ=MONTHLY', starts_at: STARTS_AT }+ logic.actions.setSchedules([first, second])+ logic.actions.selectSchedule(second)+ logic.actions.setScheduleStartsAt('2026-05-05T09:00:00.000Z')++ await expectLogic(logic, () => {+ logic.actions.saveWorkflow(logic.values.workflow)+ }).toDispatchActions(['saveWorkflowSuccess', 'setSchedules'])++ expect(logic.values.schedules.map((s) => [s.id, s.rrule])).toEqual([+ ['schedule-1', 'FREQ=WEEKLY'],+ ['schedule-2', 'FREQ=DAILY'],+ ])+ expect(logic.values.currentSchedule?.id).toBe('schedule-2')+ })+it('does not re-save when nothing changed during the round-trip', async () => {jest.useFakeTimers()diff --git a/products/workflows/frontend/Workflows/workflowLogic.ts b/products/workflows/frontend/Workflows/workflowLogic.tsindex a46508e1a74f..6a951ede36aa 100644--- a/products/workflows/frontend/Workflows/workflowLogic.ts+++ b/products/workflows/frontend/Workflows/workflowLogic.ts@@ -4566,20 +4566,20 @@ export const workflowLogic = kea<workflowLogicType>([// Each write answers with the saved schedule, so the editor rebaselines from// the response. Re-reading the list instead would leave a created schedule// unknown whenever that read failed, and the next save would add a second one.+ // A workflow can hold several schedules, so each write only swaps the one it touched.if (pendingSchedule === null && existingScheduleId) {await api.hogFlows.deleteHogFlowSchedule(workflowId, existingScheduleId)- actions.setSchedules([])+ actions.setSchedules(values.schedules.filter((s) => s.id !== existingScheduleId))} else if (pendingSchedule !== null && existingScheduleId) {- actions.setSchedules([- // The generated client answers with HogFlowScheduleApi, whose untyped- // `variables` does not satisfy the HogFlowSchedule the editor holds.- // nosemgrep: prefer-codegen-api-namespaced-workflows- await api.hogFlows.updateHogFlowSchedule(- workflowId,- existingScheduleId,- pendingSchedule- ),- ])+ // The generated client answers with HogFlowScheduleApi, whose untyped+ // `variables` does not satisfy the HogFlowSchedule the editor holds.+ // nosemgrep: prefer-codegen-api-namespaced-workflows+ const updated = await api.hogFlows.updateHogFlowSchedule(+ workflowId,+ existingScheduleId,+ pendingSchedule+ )+ actions.setSchedules(values.schedules.map((s) => (s.id === updated.id ? updated : s)))} else if (pendingSchedule !== null) {actions.setSchedules([// nosemgrep: prefer-codegen-api-namespaced-workflows