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): require a sender on email steps (#60362)

Ben Leada87cf3ebbea
diff --git a/products/workflows/frontend/Workflows/workflowLogic.emailValidation.test.ts b/products/workflows/frontend/Workflows/workflowLogic.emailValidation.test.ts
new file mode 100644
index 000000000000..2696f1a4be1c
--- /dev/null
+++ b/products/workflows/frontend/Workflows/workflowLogic.emailValidation.test.ts
@@ -0,0 +1,211 @@
+import { expectLogic } from 'kea-test-utils'
+
+import { useMocks } from '~/mocks/jest'
+import { initKeaTests } from '~/test/init'
+
+import { HogFlow, HogFlowAction } from './hogflows/types'
+import { workflowLogic } from './workflowLogic'
+
+const WORKFLOW_ID = 'wf-email-validation-1'
+const EMAIL_NODE_ID = 'email_node'
+
+const makeEmailAction = (fromValue: any): Extract<HogFlowAction, { type: 'function_email' }> => ({
+ id: EMAIL_NODE_ID,
+ type: 'function_email',
+ name: 'Send email',
+ description: '',
+ created_at: 0,
+ updated_at: 0,
+ config: {
+ template_id: 'template-email',
+ inputs: {
+ email: {
+ value: {
+ to: { email: '[email protected]' },
+ from: fromValue,
+ subject: 'Hello',
+ html: '<p>Hello</p>',
+ text: 'Hello',
+ },
+ templating: 'liquid',
+ },
+ },
+ },
+})
+
+const makeWorkflow = (fromValue: any): HogFlow => ({
+ id: WORKFLOW_ID,
+ name: 'Email validation test',
+ actions: [
+ {
+ id: 'trigger_node',
+ type: 'trigger',
+ name: 'Trigger',
+ description: '',
+ created_at: 0,
+ updated_at: 0,
+ config: { type: 'event', filters: {} },
+ },
+ makeEmailAction(fromValue),
+ {
+ id: 'exit_node',
+ type: 'exit',
+ name: 'Exit',
+ description: '',
+ created_at: 0,
+ updated_at: 0,
+ config: { reason: 'Default exit' },
+ },
+ ],
+ edges: [
+ { from: 'trigger_node', to: EMAIL_NODE_ID, type: 'continue' },
+ { from: EMAIL_NODE_ID, to: 'exit_node', type: 'continue' },
+ ],
+ conversion: { window_minutes: null, filters: [] },
+ exit_condition: 'exit_only_at_end',
+ version: 1,
+ status: 'draft',
+ team_id: 1,
+ trigger: { type: 'event', filters: {} } as HogFlow['trigger'],
+ created_at: '2026-05-01T00:00:00.000Z',
+ updated_at: '2026-05-01T00:00:00.000Z',
+})
+
+// Hangs the templates fetch so `hogFunctionTemplatesByIdLoading` stays true and the
+// function-action branch in `actionValidationErrorsById` doesn't clobber the email block.
+const hangingTemplatesEndpoint = (): Promise<unknown> => new Promise(() => {})
+
+// Matches the production template-email definition closely enough for validation:
+// a single required `native_email` input. Used to reproduce the loaded-templates state.
+const loadedTemplatesResponse = {
+ results: [
+ {
+ id: 'template-email',
+ name: 'Email',
+ type: 'destination',
+ status: 'hidden',
+ free: false,
+ inputs_schema: [
+ {
+ type: 'native_email',
+ key: 'email',
+ label: 'Email message',
+ required: true,
+ },
+ ],
+ },
+ ],
+ count: 1,
+}
+
+describe('workflowLogic email step "from" validation', () => {
+ let logic: ReturnType<typeof workflowLogic.build>
+
+ afterEach(() => {
+ logic?.unmount()
+ })
+
+ it('flags the step as invalid when "from" has an email but no integrationId (no sender picked)', async () => {
+ useMocks({
+ get: {
+ '/api/environments/:team_id/hog_flows/:id/': makeWorkflow({ email: '[email protected]' }),
+ '/api/projects/:team_id/hog_function_templates/': hangingTemplatesEndpoint,
+ },
+ })
+ initKeaTests()
+ logic = workflowLogic({ id: WORKFLOW_ID, tabId: 'default' })
+ logic.mount()
+ await expectLogic(logic).toDispatchActions(['loadWorkflowSuccess'])
+
+ const result = logic.values.actionValidationErrorsById[EMAIL_NODE_ID]
+ expect(result).not.toBeNull()
+ expect(result?.valid).toBe(false)
+ expect(result?.errors.email).toBe('Choose who to send this email from')
+ })
+
+ it('flags the step as invalid when "from" is completely missing', async () => {
+ useMocks({
+ get: {
+ '/api/environments/:team_id/hog_flows/:id/': makeWorkflow(undefined),
+ '/api/projects/:team_id/hog_function_templates/': hangingTemplatesEndpoint,
+ },
+ })
+ initKeaTests()
+ logic = workflowLogic({ id: WORKFLOW_ID, tabId: 'default' })
+ logic.mount()
+ await expectLogic(logic).toDispatchActions(['loadWorkflowSuccess'])
+
+ const result = logic.values.actionValidationErrorsById[EMAIL_NODE_ID]
+ expect(result?.valid).toBe(false)
+ expect(result?.errors.email).toContain('Choose who to send this email from')
+ })
+
+ it('flags the step as invalid when integrationId is set but from.email is missing', async () => {
+ useMocks({
+ get: {
+ '/api/environments/:team_id/hog_flows/:id/': makeWorkflow({ integrationId: 42 }),
+ '/api/projects/:team_id/hog_function_templates/': hangingTemplatesEndpoint,
+ },
+ })
+ initKeaTests()
+ logic = workflowLogic({ id: WORKFLOW_ID, tabId: 'default' })
+ logic.mount()
+ await expectLogic(logic).toDispatchActions(['loadWorkflowSuccess'])
+
+ const result = logic.values.actionValidationErrorsById[EMAIL_NODE_ID]
+ expect(result?.valid).toBe(false)
+ expect(result?.errors.email).toContain('Choose who to send this email from')
+ })
+
+ it('does not flag a "from" error when an integration sender has been picked', async () => {
+ useMocks({
+ get: {
+ '/api/environments/:team_id/hog_flows/:id/': makeWorkflow({
+ email: '[email protected]',
+ integrationId: 42,
+ }),
+ '/api/projects/:team_id/hog_function_templates/': hangingTemplatesEndpoint,
+ },
+ })
+ initKeaTests()
+ logic = workflowLogic({ id: WORKFLOW_ID, tabId: 'default' })
+ logic.mount()
+ await expectLogic(logic).toDispatchActions(['loadWorkflowSuccess'])
+
+ const result = logic.values.actionValidationErrorsById[EMAIL_NODE_ID]
+ expect(result?.errors.email).toBeUndefined()
+ expect(result?.valid).toBe(true)
+ })
+
+ it('keeps the email-block error after templates load (function-action branch must not clobber it)', async () => {
+ useMocks({
+ get: {
+ '/api/environments/:team_id/hog_flows/:id/': makeWorkflow({ email: '[email protected]' }),
+ '/api/projects/:team_id/hog_function_templates/': loadedTemplatesResponse,
+ },
+ })
+ initKeaTests()
+ logic = workflowLogic({ id: WORKFLOW_ID, tabId: 'default' })
+ logic.mount()
+ await expectLogic(logic).toDispatchActions(['loadWorkflowSuccess', 'loadHogFunctionTemplatesByIdSuccess'])
+
+ const result = logic.values.actionValidationErrorsById[EMAIL_NODE_ID]
+ expect(result?.valid).toBe(false)
+ expect(result?.errors.email).toBe('Choose who to send this email from')
+ })
+
+ it('propagates the step error into workflowHasActionErrors', async () => {
+ useMocks({
+ get: {
+ '/api/environments/:team_id/hog_flows/:id/': makeWorkflow({ email: '[email protected]' }),
+ '/api/projects/:team_id/hog_function_templates/': hangingTemplatesEndpoint,
+ },
+ })
+ initKeaTests()
+ logic = workflowLogic({ id: WORKFLOW_ID, tabId: 'default' })
+ logic.mount()
+ await expectLogic(logic).toDispatchActions(['loadWorkflowSuccess'])
+
+ expect(logic.values.workflowHasActionErrors).toBe(true)
+ })
+})
diff --git a/products/workflows/frontend/Workflows/workflowLogic.ts b/products/workflows/frontend/Workflows/workflowLogic.ts
index b757d4d0cd43..1fe338475fb4 100644
--- a/products/workflows/frontend/Workflows/workflowLogic.ts
+++ b/products/workflows/frontend/Workflows/workflowLogic.ts
@@ -474,9 +474,10 @@ export const workflowLogic = kea<workflowLogicType>([
subject: !emailValue?.subject
? 'Subject is required'
: getTemplatingError(emailValue?.subject, emailTemplating),
- from: !emailValue?.from?.email
- ? 'From is required'
- : getTemplatingError(emailValue?.from?.email, emailTemplating),
+ from:
+ !emailValue?.from?.integrationId || !emailValue?.from?.email
+ ? 'Choose who to send this email from'
+ : getTemplatingError(emailValue?.from?.email, emailTemplating),
to: !emailValue?.to?.email
? 'To is required'
: getTemplatingError(emailValue?.to?.email, emailTemplating),
@@ -502,6 +503,7 @@ export const workflowLogic = kea<workflowLogicType>([
if (!template) {
result.valid = false
result.errors = {
+ ...result.errors,
// This is a special case for the template_id field which might need to go to a generic error message
_template_id: 'Template not found',
}
@@ -510,8 +512,10 @@ export const workflowLogic = kea<workflowLogicType>([
action.config.inputs,
template.inputs_schema ?? []
)
- result.valid = configValidation.valid
- result.errors = configValidation.errors
+ // Merge so the type-specific block above (e.g. function_email's
+ // stricter `from` check) is not clobbered by the generic validator.
+ result.valid = result.valid && configValidation.valid
+ result.errors = { ...configValidation.errors, ...result.errors }
}
}