{"record":{"id":"ff14da75f6cf0109","repo":"dagger/dagger","slug":"w-workspace-arguments-are-not-inherited-by-modul","errorCode":null,"errorMessage":"%w: workspace arguments are not inherited by module runtime calls; pass a Workspace explicitly","messagePattern":"%w: workspace arguments are not inherited by module runtime calls; pass a Workspace explicitly","errorType":"exception","errorClass":"ErrNoCurrentWorkspace","httpStatus":null,"severity":"error","filePath":"core/modfunc.go","lineNumber":1274,"sourceCode":"\t// is still explicit here — the group threaded it via WorkspaceToContext —\n\t// so this does not silently inherit a caller's workspace across modules.\n\tif boundWS, ok := WorkspaceFromContext(ctx); ok {\n\t\twsID, err := boundWS.ID()\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"get bound workspace ID: %w\", err)\n\t\t}\n\t\treturn dagql.NewID[*Workspace](wsID), nil\n\t}\n\n\t// Otherwise a Workspace is auto-injected only for calls originating outside a\n\t// module function (a direct CLI/SDK client, or a schema-walking flow like\n\t// `dagger generate`). A running module function must pass a Workspace to its\n\t// dependencies explicitly, so a dependency does not silently inherit its\n\t// caller's workspace.\n\tif inModuleFunction, err := callerInModuleFunction(ctx); err != nil {\n\t\treturn nil, err\n\t} else if inModuleFunction {\n\t\treturn nil, fmt.Errorf(\"%w: workspace arguments are not inherited by module runtime calls; pass a Workspace explicitly\", ErrNoCurrentWorkspace)\n\t}\n\n\tvar ws dagql.ObjectResult[*Workspace]\n\terr := dag.Select(ctx, dag.Root(), &ws,\n\t\tdagql.Selector{\n\t\t\tField: \"currentWorkspace\",\n\t\t\tArgs: []dagql.NamedInput{\n\t\t\t\t{Name: \"skipMigrationCheck\", Value: dagql.Boolean(true)},\n\t\t\t},\n\t\t},\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"load workspace: %w\", err)\n\t}\n\n\twsID, err := ws.ID()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"get workspace ID: %w\", err)","sourceCodeStart":1256,"sourceCodeEnd":1292,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/core/modfunc.go#L1256-L1292","documentation":"Workspaces are auto-injected only for calls originating outside a module function (direct CLI/SDK or schema-walking flows like `dagger generate`). If the call is running inside a module function body and no workspace is bound in context, loadWorkspaceArg refuses to inherit the caller's workspace and returns ErrNoCurrentWorkspace with this message, preventing silent cross-module workspace inheritance.","triggerScenarios":"A module function calls another module function whose dependency declares a Workspace! (auto-inject) parameter, without passing a Workspace explicitly, from inside the module runtime.","commonSituations":"Chaining module functions where a dependency function signature gained a Workspace parameter; upgrading Dagger after this guard was introduced and previously-inheriting code now errors.","solutions":["Pass a Workspace explicitly to the dependency function from your module code","If the caller has no workspace, create one (e.g. from a Directory) before calling the dependency","If the dependency should not require a workspace, change its signature to take a Workspace explicitly or drop the auto-inject"],"exampleFix":"// before\ndep.Provider(ctx) // dependency declares Workspace! auto-inject\n// after\nws := dag.Workspace(dag.Host().Directory(\".\"))\ndep.Provider(ctx, dagql.WorkspaceInput{Workspace: ws})","handlingStrategy":"validation","validationCode":"// in module code, before calling a dependency that declares Workspace!\nif ws == nil {\n\tws = dag.Workspace(dag.Host().Directory(\".\"))\n}\n_ = ws // pass ws explicitly to the dependency call","typeGuard":null,"tryCatchPattern":"_, err := fn.Call(ctx, ...)\nif errors.Is(err, ErrNoCurrentWorkspace) {\n\t// pass an explicit Workspace to the dependency\n}","preventionTips":["Never rely on workspace auto-injection from inside a module function; always pass Workspace explicitly","Review dependency signatures for Workspace! parameters when chaining module functions","Bound workspaces in context (WorkspaceToContext) are fine; only ambient inheritance is blocked"],"tags":["dagger","workspace","module-runtime","explicit-argument"],"backgroundTag":"workspace-not-inherited","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"}