{"record":{"id":"7573f51607f7b236","repo":"argoproj/argo-workflows","slug":"failed-to-evaluate-workflow-template-expression","errorCode":null,"errorMessage":"failed to evaluate workflow template expression: %w","messagePattern":"failed to evaluate workflow template expression: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/event/dispatch/operation.go","lineNumber":94,"sourceCode":"\t\tif err != nil {\n\t\t\tlogger.WithError(err).WithFields(logging.Fields{\"namespace\": event.Namespace, \"event\": event.Name}).Error(ctx, \"failed to dispatch from event\")\n\t\t\to.eventRecorder.Event(&event, corev1.EventTypeWarning, \"WorkflowEventBindingError\", \"failed to dispatch event: \"+err.Error())\n\t\t\terrs = append(errs, err)\n\t\t}\n\t}\n\tif len(errs) > 0 {\n\t\treturn fmt.Errorf(\"failed to dispatch event: %v\", errs)\n\t}\n\treturn nil\n}\n\nfunc (o *Operation) dispatch(ctx context.Context, wfeb wfv1.WorkflowEventBinding) (*wfv1.Workflow, error) {\n\tlogger := logging.RequireLoggerFromContext(ctx)\n\n\tselector := wfeb.Spec.Event.Selector\n\tmatched, err := argoexpr.EvalBool(selector, o.env)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to evaluate workflow template expression: %w\", err)\n\t}\n\tlogger.WithFields(logging.Fields{\"namespace\": wfeb.Namespace, \"event\": wfeb.Name, \"selector\": selector, \"matched\": matched}).Debug(ctx, \"Selector evaluation\")\n\tsubmit := wfeb.Spec.Submit\n\tif matched && submit != nil {\n\t\t//nolint: contextcheck\n\t\tclient := auth.GetWfClient(o.ctx)\n\t\tref := wfeb.Spec.Submit.WorkflowTemplateRef\n\t\tvar tmpl wfv1.WorkflowSpecHolder\n\t\tvar err error\n\t\tif ref.ClusterScope {\n\t\t\ttmpl, err = client.ArgoprojV1alpha1().ClusterWorkflowTemplates().Get(ctx, ref.Name, metav1.GetOptions{})\n\t\t} else {\n\t\t\ttmpl, err = client.ArgoprojV1alpha1().WorkflowTemplates(wfeb.Namespace).Get(ctx, ref.Name, metav1.GetOptions{})\n\t\t}\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to get workflow template: %w\", err)\n\t\t}\n\t\terr = o.instanceIDService.Validate(tmpl)","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/server/event/dispatch/operation.go#L76-L112","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before (typo + unguarded nil)\nselector: pyload.event == \"push\"\n# after\nselector: payload != nil && payload.event == \"push\"","handlingStrategy":"validation","validationCode":"// validate selector compiles against the expected env before applying the wfeb\nenv := map[string]any{\"payload\": map[string]any{}, \"discriminator\": \"\", \"namespace\": ns}\nif _, err := expr.Compile(wfeb.Spec.Event.Selector, expr.Env(env), expr.AsBool()); err != nil {\n\treturn fmt.Errorf(\"invalid selector %q: %w\", wfeb.Spec.Event.Selector, err)\n}","typeGuard":null,"tryCatchPattern":"matched, err := argoexpr.EvalBool(selector, env)\nif err != nil {\n\t// \"failed to evaluate workflow template expression\"\n\t// fix selector syntax/identifiers, then re-test with argo events test\n}","preventionTips":["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 ...`"],"tags":["expression","eventbinding","selector","events"],"backgroundTag":"selector-expression-evaluation-failed","analyzedSha":"35bff19146f5a6ada77468c431f2624bd577e373","analyzedAt":"2026-09-03T19:34:35.908Z","contentChangedAt":"2026-09-03T19:34:35.908Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}