{"record":{"id":"698609a1319525cd","repo":"dagger/dagger","slug":"expected-instance-of-t-got-t","errorCode":null,"errorMessage":"expected instance of %T, got %T","messagePattern":"expected instance of %T, got %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dagql/objects.go","lineNumber":868,"sourceCode":"\n\t\t\treturn NewResultForCurrentCall(ctx, res)\n\t\t},\n\t}\n\n\tif cacheFn != nil {\n\t\tfield.Spec.GetDynamicInput = func(ctx context.Context, self AnyResult, argVals map[string]Input, view call.View, req *CallRequest) error {\n\t\t\tif argsErr != nil {\n\t\t\t\t// this error is deferred until runtime, since it's better (at least\n\t\t\t\t// more testable) than panicking\n\t\t\t\treturn argsErr\n\t\t\t}\n\t\t\tvar args A\n\t\t\tif err := spec.Args.Decode(argVals, &args, view); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tinst, ok := self.(ObjectResult[T])\n\t\t\tif !ok {\n\t\t\t\treturn fmt.Errorf(\"expected instance of %T, got %T\", field, self)\n\t\t\t}\n\t\t\treturn cacheFn(ctx, inst, args, req)\n\t\t}\n\t}\n\n\treturn field\n}\n\n// FieldSpec is a specification for a field.\ntype FieldSpec struct {\n\t// Name is the name of the field.\n\tName string\n\t// Description is the description of the field.\n\tDescription string\n\t// Args is the list of arguments that the field accepts.\n\tArgs InputSpecs\n\t// Type is the type of the field's result.\n\tType Typed","sourceCodeStart":850,"sourceCodeEnd":886,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/dagql/objects.go#L850-L886","documentation":"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).","triggerScenarios":"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.","commonSituations":"Copy-pasted field specs across object types; generic mis-parameterization when defining fields; custom servers wiring the wrong instance into Select.","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."],"exampleFix":"// before\nvar wrong = dagql.Field(containerClass, \"name\", ...) // called with pipelineInstance\n// after\npipelineClass.Fields.Add(\"name\", ...) // invoke on an ObjectResult[Pipeline]","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func asObjectResult[T any](self any) (ObjectResult[T], bool) {\n    inst, ok := self.(ObjectResult[T])\n    return inst, ok\n}","tryCatchPattern":"err := classCall(ctx)\nif err != nil && strings.Contains(err.Error(), \"expected instance of\") {\n    log.Fatalf(\"field invoked with wrong instance type: %v\", err)\n}","preventionTips":["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."],"tags":["dagql","go","generics","type-mismatch","graphql"],"backgroundTag":"type-mismatch","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}