Skip to content

: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.

fix(workflows): load schedules for workflows on any trigger (#127335)

Harley Alexander3cf7c2af83ef
diff --git a/products/workflows/frontend/Workflows/workflowLogic.schedule.test.ts b/products/workflows/frontend/Workflows/workflowLogic.schedule.test.ts
index 89991beb8949..24bd493a9476 100644
--- a/products/workflows/frontend/Workflows/workflowLogic.schedule.test.ts
+++ b/products/workflows/frontend/Workflows/workflowLogic.schedule.test.ts
@@ -497,4 +497,29 @@ describe('workflowLogic schedule reducers', () => {
expect(logic.values.schedules.map((s) => s.id)).toEqual(['schedule-1', 'schedule-2'])
})
})
+
+ describe('loading a workflow', () => {
+ it('loads a schedule left behind when the trigger is no longer a schedule', async () => {
+ useMocks({
+ get: {
+ '/api/environments/:team_id/hog_flows/:id/': {
+ id: 'wf-manual',
+ name: 'Switched to manual',
+ actions: [],
+ trigger: { type: 'manual' },
+ },
+ '/api/environments/:team_id/hog_flows/:id/schedules/': [makeSchedule()],
+ '/api/projects/:team_id/hog_function_templates/': { results: [], count: 0 },
+ },
+ })
+ logic.unmount()
+ logic = workflowLogic({ id: 'wf-manual' })
+ logic.mount()
+
+ await expectLogic(logic).toDispatchActions(['loadWorkflowSuccess', 'setSchedules']).toFinishAllListeners()
+
+ expect(logic.values.currentSchedule?.id).toBe('schedule-1')
+ expect(logic.values.pendingSchedule).toBe(false)
+ })
+ })
})
diff --git a/products/workflows/frontend/Workflows/workflowLogic.ts b/products/workflows/frontend/Workflows/workflowLogic.ts
index 2543cc0f48a6..01d0b2903740 100644
--- a/products/workflows/frontend/Workflows/workflowLogic.ts
+++ b/products/workflows/frontend/Workflows/workflowLogic.ts
@@ -65,12 +65,7 @@ import {
} from './hogflows/steps/components/rrule-helpers'
import type { ScheduleState } from './hogflows/steps/components/rrule-helpers'
import { getTemplatingError } from './hogflows/steps/templatingError'
-import {
- HogFlowActionSchema,
- SCHEDULED_TRIGGER_TYPES,
- isFunctionAction,
- isTriggerFunction,
-} from './hogflows/steps/types'
+import { HogFlowActionSchema, isFunctionAction, isTriggerFunction } from './hogflows/steps/types'
import {
type HogFlow,
type HogFlowAction,
@@ -4548,8 +4543,9 @@ export const workflowLogic = kea<workflowLogicType>([
// The form edits the staged draft when one exists; the live config keeps running underneath.
actions.resetWorkflow(withStagedDraft(originalWorkflow))
actions.replayDeferredResourceEdited()
- const triggerType = originalWorkflow.trigger?.type
- if (originalWorkflow.id && SCHEDULED_TRIGGER_TYPES.includes(triggerType ?? '')) {
+ // Load schedules whatever the trigger is. A schedule outlives a switch to another trigger,
+ // and a save that cannot see it creates a second one that fires next to it.
+ if (originalWorkflow.id) {
try {
const schedules = await api.hogFlows.getHogFlowSchedules(originalWorkflow.id)
actions.setSchedules(schedules)