gohugoio/hugo · error
can't apply myself (no turtles allowed)
Error message
can't apply myself (no turtles allowed)
What it means
`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.
Source
Thrown at tpl/collections/apply.go:33
import (
"context"
"errors"
"fmt"
"reflect"
"strings"
"github.com/gohugoio/hugo/common/hreflect"
)
// Apply takes an array or slice c and returns a new slice with the function fname applied over it.
func (ns *Namespace) Apply(ctx context.Context, c any, fname string, args ...any) (any, error) {
if c == nil {
return make([]any, 0), nil
}
if fname == "apply" {
return nil, errors.New("can't apply myself (no turtles allowed)")
}
seqv := reflect.ValueOf(c)
seqv, isNil := hreflect.Indirect(seqv)
if isNil {
return nil, errors.New("can't iterate over a nil value")
}
fnv, found := ns.lookupFunc(ctx, fname)
if !found {
return nil, errors.New("can't find function " + fname)
}
switch seqv.Kind() {
case reflect.Array, reflect.Slice:
r := make([]any, seqv.Len())
for i := range seqv.Len() {
vv := seqv.Index(i)View on GitHub ↗ (pinned to 8a468df065)
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.
Example fix
<!-- before -->
{{ $r := apply $seqOfSeqs "apply" "." "upper" "." }}
<!-- after -->
{{ $r := slice }}
{{ range $seqOfSeqs }}
{{ $r = $r | append (apply . "upper" ".") }}
{{ end }} Defensive patterns
Strategy: validation
Validate before calling
{{/* never pass "apply" as the function name to apply */}}
{{ $upper := apply $seq "strings.ToUpper" "." }} Prevention
- 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
When it happens
Trigger: Calling `{{ apply $seq "apply" ... }}` — passing the literal function name "apply" as the function to apply.
Common situations: Attempting to nest apply calls to map a function over a slice of slices; generating the function name dynamically and it resolving to "apply".
Related errors
- can't find function %s
- symdiff: failed to convert value: %w
- arguments to symdiff must be slices or arrays
- errWrongArgStructure
- errKeyIsEmptyString
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/6914ef185238a331.json.
Report an issue: GitHub ↗.