argoproj/argo-workflows · error
failed to evaluate workflow template expression: %w
Error message
failed to evaluate workflow template expression: %w
What it means
dispatch evaluates each WorkflowEventBinding's spec.event.selector as a boolean expression (expr-lang) against the operation's environment. If the expression is syntactically invalid or references unknown identifiers, argoexpr.EvalBool errors and is wrapped with this message; the binding is skipped and contributes to Dispatch's aggregate error (308).
Source
Thrown at server/event/dispatch/operation.go:94
if err != nil {
logger.WithError(err).WithFields(logging.Fields{"namespace": event.Namespace, "event": event.Name}).Error(ctx, "failed to dispatch from event")
o.eventRecorder.Event(&event, corev1.EventTypeWarning, "WorkflowEventBindingError", "failed to dispatch event: "+err.Error())
errs = append(errs, err)
}
}
if len(errs) > 0 {
return fmt.Errorf("failed to dispatch event: %v", errs)
}
return nil
}
func (o *Operation) dispatch(ctx context.Context, wfeb wfv1.WorkflowEventBinding) (*wfv1.Workflow, error) {
logger := logging.RequireLoggerFromContext(ctx)
selector := wfeb.Spec.Event.Selector
matched, err := argoexpr.EvalBool(selector, o.env)
if err != nil {
return nil, fmt.Errorf("failed to evaluate workflow template expression: %w", err)
}
logger.WithFields(logging.Fields{"namespace": wfeb.Namespace, "event": wfeb.Name, "selector": selector, "matched": matched}).Debug(ctx, "Selector evaluation")
submit := wfeb.Spec.Submit
if matched && submit != nil {
//nolint: contextcheck
client := auth.GetWfClient(o.ctx)
ref := wfeb.Spec.Submit.WorkflowTemplateRef
var tmpl wfv1.WorkflowSpecHolder
var err error
if ref.ClusterScope {
tmpl, err = client.ArgoprojV1alpha1().ClusterWorkflowTemplates().Get(ctx, ref.Name, metav1.GetOptions{})
} else {
tmpl, err = client.ArgoprojV1alpha1().WorkflowTemplates(wfeb.Namespace).Get(ctx, ref.Name, metav1.GetOptions{})
}
if err != nil {
return nil, fmt.Errorf("failed to get workflow template: %w", err)
}
err = o.instanceIDService.Validate(tmpl)View on GitHub (pinned to 35bff19146)
Solutions
- Inspect the selector: `kubectl get wfeb <name> -n <ns> -o jsonpath='{.spec.event.selector}'` and validate expr syntax (https://expr-lang.org playground).
- Only reference defined identifiers: `payload`, `discriminator`, `namespace` (per event binding docs).
- Guard nil/missing fields: prefix comparisons with `field != nil &&`.
- Re-test the binding: `argo events test <wfeb> --payload '{...}'` to evaluate the selector without waiting for a real webhook.
- Fix YAML quoting (wrap selector in single quotes) so the shell/kubectl didn't strip characters.
Example fix
# before (typo + unguarded nil) selector: pyload.event == "push" # after selector: payload != nil && payload.event == "push"
Defensive patterns
Strategy: validation
Validate before calling
// validate selector compiles against the expected env before applying the wfeb
env := map[string]any{"payload": map[string]any{}, "discriminator": "", "namespace": ns}
if _, err := expr.Compile(wfeb.Spec.Event.Selector, expr.Env(env), expr.AsBool()); err != nil {
return fmt.Errorf("invalid selector %q: %w", wfeb.Spec.Event.Selector, err)
} Try / catch
matched, err := argoexpr.EvalBool(selector, env)
if err != nil {
// "failed to evaluate workflow template expression"
// fix selector syntax/identifiers, then re-test with argo events test
} Prevention
- Compile-test selectors with expr.Env before applying the binding
- Only use documented identifiers: payload, discriminator, namespace
- Prefix optional payload paths with nil checks
- Quote selector strings in YAML to avoid shell/kubectl mangling
- Validate with `argo events test <wfeb> --payload ...`
When it happens
Trigger: Selector with bad syntax (`= =`, unbalanced quotes), referencing undefined variables (typo like `paylod` instead of `payload`, `discriminator` misuse), or calling unknown functions in the selector string of a WorkflowEventBinding.
Common situations: Typos in payload paths; selectors copied from Workflow examples that used different variable names; special characters from shell quoting mangled when applying YAML; expression referencing fields absent for some event types hitting that binding.
Related errors
AI-assisted analysis of argoproj/argo-workflows@35bff19146 (2026-09-03).
Data as JSON: /api/errors/7573f51607f7b236.
Report an issue: GitHub.