dagger/dagger · error
expected instance of %T, got %T
Error message
expected instance of %T, got %T
What it means
In a cached field spec, dagql asserts that the `self` receiver passed in implements ObjectResult[T] for the field's declared type T before invoking cacheFn. If it does not (type assertion fails), this error reports the expected field type and the actual self type (dagql/objects.go:868).
Source
Thrown at dagql/objects.go:868
return NewResultForCurrentCall(ctx, res)
},
}
if cacheFn != nil {
field.Spec.GetDynamicInput = func(ctx context.Context, self AnyResult, argVals map[string]Input, view call.View, req *CallRequest) error {
if argsErr != nil {
// this error is deferred until runtime, since it's better (at least
// more testable) than panicking
return argsErr
}
var args A
if err := spec.Args.Decode(argVals, &args, view); err != nil {
return err
}
inst, ok := self.(ObjectResult[T])
if !ok {
return fmt.Errorf("expected instance of %T, got %T", field, self)
}
return cacheFn(ctx, inst, args, req)
}
}
return field
}
// FieldSpec is a specification for a field.
type FieldSpec struct {
// Name is the name of the field.
Name string
// Description is the description of the field.
Description string
// Args is the list of arguments that the field accepts.
Args InputSpecs
// Type is the type of the field's result.
Type TypedView on GitHub (pinned to 82ba2681db)
Solutions
- Ensure the field is invoked on an instance of the same object type it was defined for (matching T in ObjectResult[T]).
- Check the ObjectSpec/field registration: the field should be added to the class of the object type it operates on.
- Fix any generic type parameter mismatch in the Field/cacheFn definition so T matches the instance type.
Example fix
// before
var wrong = dagql.Field(containerClass, "name", ...) // called with pipelineInstance
// after
pipelineClass.Fields.Add("name", ...) // invoke on an ObjectResult[Pipeline] Defensive patterns
Strategy: type-guard
Type guard
func asObjectResult[T any](self any) (ObjectResult[T], bool) {
inst, ok := self.(ObjectResult[T])
return inst, ok
} Try / catch
err := classCall(ctx)
if err != nil && strings.Contains(err.Error(), "expected instance of") {
log.Fatalf("field invoked with wrong instance type: %v", err)
} Prevention
- Register each field on the class matching its receiver type; avoid sharing field specs across classes.
- Keep generic type parameters consistent when defining Field/cacheFn.
- Add unit tests that invoke every registered field once to surface type mismatches early.
When it happens
Trigger: Registering/calling a cached field with a self value whose concrete type differs from the ObjectResult[T] the field spec was built for — e.g. mixing object classes, calling a field of type A on an instance of type B.
Common situations: Copy-pasted field specs across object types; generic mis-parameterization when defining fields; custom servers wiring the wrong instance into Select.
Related errors
- %T.ConvertToSDKInput: expected Enumerable, got %T: %#v
- %T.CollectContent: expected Enumerable, got %T: %#v
- %T.ConvertToSDKInput: expected Derefable, got %T: %#v
- init arg %q value as %T (%s) using %T: %w
- call %s.%s: current client metadata: %w
AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05).
Data as JSON: /api/errors/698609a1319525cd.
Report an issue: GitHub.