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): point at the failing step when enabling a workflow (#68951)

Harley Alexander3b0f1f2b967a
diff --git a/frontend/src/lib/components/CyclotronJob/CyclotronJobInputsValidation.test.ts b/frontend/src/lib/components/CyclotronJob/CyclotronJobInputsValidation.test.ts
index c326e88b2f00..ed884bae85b9 100644
--- a/frontend/src/lib/components/CyclotronJob/CyclotronJobInputsValidation.test.ts
+++ b/frontend/src/lib/components/CyclotronJob/CyclotronJobInputsValidation.test.ts
@@ -421,6 +421,24 @@ describe('CyclotronJobInputsValidation', () => {
templating: 'hog',
expected: W.liquidSyntaxInHogField,
},
+ {
+ name: 'hog field, liquid pipe filter without a global reference',
+ value: '{{ user.name | upcase }}',
+ templating: 'hog',
+ expected: W.liquidSyntaxInHogField,
+ },
+ {
+ name: 'hog field, liquid pipe filter embedded in literal text',
+ value: 'Cart abandoned by {{ email | default: "someone" }}',
+ templating: 'hog',
+ expected: W.liquidSyntaxInHogField,
+ },
+ {
+ name: 'hog field, liquid tag syntax',
+ value: '{% if abandoned %}Reminder{% endif %}',
+ templating: 'hog',
+ expected: W.liquidSyntaxInHogField,
+ },
{
name: 'liquid field, hog single-brace syntax referencing a global',
value: '{person.properties.email}',
@@ -464,6 +482,18 @@ describe('CyclotronJobInputsValidation', () => {
templating: 'hog',
expected: undefined,
},
+ {
+ name: 'hog field, hog OR operator inside single braces',
+ value: "{person.properties.email || 'unknown'}",
+ templating: 'hog',
+ expected: undefined,
+ },
+ {
+ name: 'hog field, pipe in literal text outside braces',
+ value: 'status | pending',
+ templating: 'hog',
+ expected: undefined,
+ },
{
name: 'liquid field, braces that are not a global reference',
value: '{"key": "value"}',
diff --git a/frontend/src/lib/components/CyclotronJob/CyclotronJobInputsValidation.ts b/frontend/src/lib/components/CyclotronJob/CyclotronJobInputsValidation.ts
index 933a017bb4bd..306a3f6e41ee 100644
--- a/frontend/src/lib/components/CyclotronJob/CyclotronJobInputsValidation.ts
+++ b/frontend/src/lib/components/CyclotronJob/CyclotronJobInputsValidation.ts
@@ -64,8 +64,14 @@ const detectTemplatingMismatch = (value: unknown, language: 'hog' | 'liquid'): s
return
}
- // Hog field
- if (new RegExp(`\\{\\{[^}]*${GLOBAL_REFERENCE}[^}]*\\}\\}`).test(value)) {
+ // Hog field. Beyond `{{ global.… }}`, a pipe filter inside double braces (`{{ x | upcase }}`)
+ // or a `{% … %}` tag is unambiguously Liquid regardless of what it references — Hog has no
+ // single-pipe operator and no percent tags, so these fail Hog compilation at activation.
+ if (
+ new RegExp(`\\{\\{[^}]*${GLOBAL_REFERENCE}[^}]*\\}\\}`).test(value) ||
+ /\{\{[^{}]*\|[^{}]*\}\}/.test(value) ||
+ /\{%[\s\S]*?%\}/.test(value)
+ ) {
return TEMPLATING_MISMATCH_WARNINGS.liquidSyntaxInHogField
}
}
diff --git a/products/workflows/backend/api/hog_flow.py b/products/workflows/backend/api/hog_flow.py
index c18247958e40..0b6f58fbbea4 100644
--- a/products/workflows/backend/api/hog_flow.py
+++ b/products/workflows/backend/api/hog_flow.py
@@ -3,7 +3,7 @@ import json
import uuid as uuid_mod
import dataclasses
from datetime import timedelta
-from typing import Optional, cast
+from typing import Any, Optional, cast
from django.core.exceptions import ValidationError as DjangoValidationError
from django.db import transaction
@@ -126,6 +126,34 @@ def _validation_error_message(error: exceptions.ValidationError) -> str:
return str(detail)
+def _first_error_string(detail: Any) -> Optional[str]:
+ if isinstance(detail, str):
+ return detail
+ if isinstance(detail, list):
+ for item in detail:
+ if message := _first_error_string(item):
+ return message
+ if isinstance(detail, dict):
+ for value in detail.values():
+ if message := _first_error_string(value):
+ return message
+ return None
+
+
+def _describe_action_errors(errors: list[Any], actions: list[dict]) -> str:
+ # The many=True error list mirrors the actions list, with {} entries for valid actions. Raising it
+ # as-is gets flattened by the exception handler to that first empty dict, so the client sees "{}".
+ # Name each offending step instead so the error points at what to fix.
+ parts = []
+ for action_data, error in zip(actions, errors):
+ if not error:
+ continue
+ message = _first_error_string(error) or "has an invalid configuration"
+ name = action_data.get("name") if isinstance(action_data, dict) else None
+ parts.append(f"step '{name or 'unnamed'}': {message}")
+ return f"Can't enable this workflow. Fix {'; '.join(parts) or 'the invalid steps'} and try again."
+
+
def _should_validate_strictly(context: dict, is_draft: Optional[bool]) -> bool:
# Non-draft saves always validate fully. Drafts stay lenient for the web UI builder (which saves
# incomplete graphs mid-edit) and for internal re-saves (e.g. the refresh management command), which
@@ -921,7 +949,10 @@ class HogFlowSerializer(HogFlowMinimalSerializer):
status = data.get("status", instance.status if instance else "draft")
if status == "active" and instance and instance.status != "active" and "actions" not in data:
action_serializer = HogFlowActionSerializer(data=instance.actions, many=True, context=self.context)
- action_serializer.is_valid(raise_exception=True)
+ if not action_serializer.is_valid():
+ # many=True yields a list of per-action errors despite the ReturnDict annotation
+ action_errors = cast(list[Any], action_serializer.errors)
+ raise serializers.ValidationError({"actions": _describe_action_errors(action_errors, instance.actions)})
actions = action_serializer.validated_data
# The trigger is derived from the actions. We can trust the action level validation and pull it out
diff --git a/products/workflows/backend/api/test/test_hog_flow.py b/products/workflows/backend/api/test/test_hog_flow.py
index 13dc15591545..e5dbcca94004 100644
--- a/products/workflows/backend/api/test/test_hog_flow.py
+++ b/products/workflows/backend/api/test/test_hog_flow.py
@@ -310,6 +310,27 @@ class TestHogFlowAPI(APIBaseTest):
"type": "validation_error",
}
+ def test_activating_draft_with_invalid_template_names_offending_step(self):
+ hog_flow, action = self._create_hog_flow_with_action(
+ {
+ "template_id": "template-webhook",
+ # Liquid-style syntax in a Hog-templated input: web drafts store it leniently,
+ # so the compile error only surfaces on activation.
+ "inputs": {"url": {"value": "{{ person.properties.email | upcase }}"}},
+ }
+ )
+ action["name"] = "Send webhook"
+ create_response = self.client.post(f"/api/projects/{self.team.id}/hog_flows", hog_flow)
+ assert create_response.status_code == 201, create_response.json()
+ flow_id = create_response.json()["id"]
+
+ # Status-only activation (the workflows list toggle) re-validates the stored actions
+ response = self.client.patch(f"/api/projects/{self.team.id}/hog_flows/{flow_id}", {"status": "active"})
+ assert response.status_code == 400, response.json()
+ detail = response.json()["detail"]
+ assert "Send webhook" in detail, response.json()
+ assert "Invalid template" in detail, response.json()
+
def test_hog_flow_bytecode_compilation(self):
hog_flow, action = self._create_hog_flow_with_action(
{
diff --git a/products/workflows/frontend/Workflows/hogflows/steps/StepFunction.tsx b/products/workflows/frontend/Workflows/hogflows/steps/StepFunction.tsx
index f2f2a00f3484..140ba2da7c3d 100644
--- a/products/workflows/frontend/Workflows/hogflows/steps/StepFunction.tsx
+++ b/products/workflows/frontend/Workflows/hogflows/steps/StepFunction.tsx
@@ -24,6 +24,7 @@ export function StepFunctionConfiguration({ node }: { node: StepFunctionNode }):
mappings={mappings}
setMappings={(mappings) => partialSetWorkflowActionConfig(node.id, { mappings })}
errors={validationResult?.errors}
+ warnings={validationResult?.warnings}
/>
</>
)
diff --git a/products/workflows/frontend/Workflows/hogflows/steps/StepTrigger.tsx b/products/workflows/frontend/Workflows/hogflows/steps/StepTrigger.tsx
index f252a7117b21..79dc12d734a9 100644
--- a/products/workflows/frontend/Workflows/hogflows/steps/StepTrigger.tsx
+++ b/products/workflows/frontend/Workflows/hogflows/steps/StepTrigger.tsx
@@ -471,6 +471,7 @@ function StepTriggerConfigurationWebhook({
})
}
errors={validationResult?.errors}
+ warnings={validationResult?.warnings}
/>
</div>
)
@@ -680,6 +681,7 @@ function StepTriggerConfigurationTrackingPixel({
})
}
errors={validationResult?.errors}
+ warnings={validationResult?.warnings}
/>
</>
)
diff --git a/products/workflows/frontend/Workflows/hogflows/steps/components/HogFlowFunctionConfiguration.tsx b/products/workflows/frontend/Workflows/hogflows/steps/components/HogFlowFunctionConfiguration.tsx
index 5ed35fe2dc7d..b86b8bf3b250 100644
--- a/products/workflows/frontend/Workflows/hogflows/steps/components/HogFlowFunctionConfiguration.tsx
+++ b/products/workflows/frontend/Workflows/hogflows/steps/components/HogFlowFunctionConfiguration.tsx
@@ -24,6 +24,7 @@ export function HogFlowFunctionConfiguration({
mappings,
setMappings,
errors,
+ warnings,
}: {
templateId: string
inputs: Record<string, CyclotronJobInputType>
@@ -31,6 +32,7 @@ export function HogFlowFunctionConfiguration({
setInputs: (inputs: Record<string, CyclotronJobInputType>) => void
setMappings?: (mappings: HogFunctionMappingType[]) => void
errors?: Record<string, string>
+ warnings?: Record<string, string>
}): JSX.Element {
const { workflow, hogFunctionTemplatesById, hogFunctionTemplatesByIdLoading } = useValues(workflowLogic)
const { currentTeam, currentTeamLoading } = useValues(teamLogic)
@@ -129,6 +131,7 @@ export function HogFlowFunctionConfiguration({
<>
<CyclotronJobInputs
errors={errors}
+ warnings={warnings}
configuration={{
inputs: inputs as Record<string, CyclotronJobInputType>,
inputs_schema: template?.inputs_schema ?? [],
diff --git a/products/workflows/frontend/Workflows/hogflows/steps/components/StepView.tsx b/products/workflows/frontend/Workflows/hogflows/steps/components/StepView.tsx
index 45b0f77c42b7..a27ff01dfeb5 100644
--- a/products/workflows/frontend/Workflows/hogflows/steps/components/StepView.tsx
+++ b/products/workflows/frontend/Workflows/hogflows/steps/components/StepView.tsx
@@ -85,6 +85,7 @@ export function StepView({ action }: { action: HogFlowAction }): JSX.Element {
}, [action, isSelected, Step])
const hasValidationError = actionValidationErrorsById[action.id]?.valid === false
+ const hasValidationWarning = Object.keys(actionValidationErrorsById[action.id]?.warnings ?? {}).length > 0
const isAnimationTarget = mode === 'test' && animatingEdgePair?.endsWith(`->${action.id}`)
return (
@@ -243,7 +244,7 @@ export function StepView({ action }: { action: HogFlowAction }): JSX.Element {
</div>
)}
</div>
- {hasValidationError ? (
+ {hasValidationError || hasValidationWarning ? (
<div className="absolute top-0 right-0 scale-75">
<LemonBadge status="warning" size="small" content="!" position="top-right" />
</div>