{"record":{"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/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/collections/apply.go#L15-L51","documentation":"Apply (apply.go:32-34) explicitly refuses fname == \"apply\" to prevent infinite recursion (the \"no turtles\" / no infinite-turtle-stack rule). Even if a function named apply existed, the self-call is blocked before lookup.","triggerScenarios":"{{ apply .Items \"apply\" \"arg\" }} or any call where the second argument (fname) is the literal string \"apply\".","commonSituations":"Copy-paste of an apply template that left the function name as apply; attempting to nest apply on itself for chained transformation.","solutions":["Use a real registered function name as the apply target","For chained transformations, apply a named partial or compose funcs instead of self-application"],"exampleFix":"// before\n{{ apply .Items \"apply\" \".\" }}\n// after\n{{ apply .Items \"upper\" \".\" }}","handlingStrategy":"validation","validationCode":"{{ $fname := \"upper\" }}\n{{ if ne $fname \"apply\" }}\n  {{ apply . $fname \".\" }}\n{{ end }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass \"apply\" as the function name to apply","Keep a list of allowed target function names if fname is dynamic","Document that apply is non-recursive by design"],"tags":["hugo","go-template","collections","recursion","safety-guard"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}