gohugoio/hugo · error

can't apply myself (no turtles allowed)

Error message

can't apply myself (no turtles allowed)

What it means

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.

Solutions

  1. Use a real registered function name as the apply target
  2. For chained transformations, apply a named partial or compose funcs instead of self-application

Example fix

// before
{{ apply .Items "apply" "." }}
// after
{{ apply .Items "upper" "." }}
Defensive patterns

Strategy: validation

Validate before calling

{{ $fname := "upper" }}
{{ if ne $fname "apply" }}
  {{ apply . $fname "." }}
{{ end }}

Prevention

When it happens

Trigger: {{ apply .Items "apply" "arg" }} or any call where the second argument (fname) is the literal string "apply".

Common situations: Copy-paste of an apply template that left the function name as apply; attempting to nest apply on itself for chained transformation.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/6914ef185238a331. Report an issue: GitHub.

Appendix: 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 52c9bd7908)