{"id":"6914ef185238a331","repo":"gohugoio/hugo","slug":"can-t-apply-myself-no-turtles-allowed","errorCode":null,"errorMessage":"can't apply myself (no turtles allowed)","messagePattern":"can't apply myself \\(no turtles allowed\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/collections/apply.go","lineNumber":33,"sourceCode":"\nimport (\n\t\"context\"\n\t\"errors\"\n\t\"fmt\"\n\t\"reflect\"\n\t\"strings\"\n\n\t\"github.com/gohugoio/hugo/common/hreflect\"\n)\n\n// Apply takes an array or slice c and returns a new slice with the function fname applied over it.\nfunc (ns *Namespace) Apply(ctx context.Context, c any, fname string, args ...any) (any, error) {\n\tif c == nil {\n\t\treturn make([]any, 0), nil\n\t}\n\n\tif fname == \"apply\" {\n\t\treturn nil, errors.New(\"can't apply myself (no turtles allowed)\")\n\t}\n\n\tseqv := reflect.ValueOf(c)\n\tseqv, isNil := hreflect.Indirect(seqv)\n\tif isNil {\n\t\treturn nil, errors.New(\"can't iterate over a nil value\")\n\t}\n\n\tfnv, found := ns.lookupFunc(ctx, fname)\n\tif !found {\n\t\treturn nil, errors.New(\"can't find function \" + fname)\n\t}\n\n\tswitch seqv.Kind() {\n\tcase reflect.Array, reflect.Slice:\n\t\tr := make([]any, seqv.Len())\n\t\tfor i := range seqv.Len() {\n\t\t\tvv := seqv.Index(i)","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/collections/apply.go#L15-L51","documentation":"`collections.Apply` maps a named template function over each element of a slice. Hugo explicitly forbids `fname` being `\"apply\"` itself, because letting apply invoke apply would allow unbounded recursive self-application (\"turtles all the way down\"); it rejects the call up front.","triggerScenarios":"Calling `{{ apply $seq \"apply\" ... }}` — passing the literal function name \"apply\" as the function to apply.","commonSituations":"Attempting to nest apply calls to map a function over a slice of slices; generating the function name dynamically and it resolving to \"apply\".","solutions":["Restructure nested mapping with `range` instead: loop the outer slice and call `apply` on each inner slice.","Use a different function name — apply any function except apply itself.","If the name is computed, validate it before the call."],"exampleFix":"<!-- before -->\n{{ $r := apply $seqOfSeqs \"apply\" \".\" \"upper\" \".\" }}\n<!-- after -->\n{{ $r := slice }}\n{{ range $seqOfSeqs }}\n  {{ $r = $r | append (apply . \"upper\" \".\") }}\n{{ end }}","handlingStrategy":"validation","validationCode":"{{/* never pass \"apply\" as the function name to apply */}}\n{{ $upper := apply $seq \"strings.ToUpper\" \".\" }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["apply cannot invoke itself — never use \"apply\" as the function-name argument","For nested per-element transformations, use range with an inner apply-free expression, or chain multiple apply calls sequentially","Restructure recursive-looking logic into partials called with `partial` instead"],"tags":["hugo","templates","collections","apply","recursion"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}