{"record":{"id":"0ad45705edadda6e","repo":"Budibase/budibase","slug":"could-not-determine-workspace-for-project-import","errorCode":null,"errorMessage":"Could not determine workspace for Project import","messagePattern":"Could not determine workspace for Project import","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/server/src/sdk/workspace/projects/backups/imports.ts","lineNumber":1084,"sourceCode":"            name: doc.name || \"Unknown\",\n            reason:\n              \"Agent integration secrets are excluded from Project exports and must be reconfigured after import.\",\n          },\n        ]\n      }\n    }\n\n    return []\n  })\n}\n\nexport async function importProject(\n  file: { path: string },\n  opts?: { encryptPassword?: string }\n): Promise<ImportProjectResponse> {\n  const workspaceId = context.getWorkspaceId()\n  if (!workspaceId) {\n    throw new Error(\"Could not determine workspace for Project import\")\n  }\n\n  const extracted = await extractProjectPackage(file, opts?.encryptPassword)\n  const insertedDocs: InsertedDocRef[] = []\n  let importedProject: Project | undefined\n  try {\n    importedProject = await sdk.projects.create({\n      name: extracted.project.name,\n      description: extracted.project.description,\n      color: extracted.project.color,\n    })\n    const importedProjectId = importedProject._id!\n\n    const idMap = new Map<string, string>([\n      [extracted.project._id!, importedProjectId],\n      [extracted.manifest.sourceWorkspace.id, workspaceId],\n    ])\n","sourceCodeStart":1066,"sourceCodeEnd":1102,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/projects/backups/imports.ts#L1066-L1102","documentation":"importProject requires a workspace (app) context because the imported Project must be created inside a target workspace. The request context has no workspace id, so the function fails fast with a plain Error (not an HTTPError).","triggerScenarios":"Calling importProject outside of a workspace-scoped request context: background scripts hitting the SDK directly, cron jobs, or API routes that did not resolve/set the workspace (missing appId header, wrong URL path, context not opened).","commonSituations":"Custom endpoints or scripts importing packages without wrapping the call in context with a workspace id; calling from the worker in a job that did not carry the appId through; proxy mis-routing so the app id is not extracted.","solutions":["Ensure the import is invoked within a request that includes the workspace/app id (e.g. appId header or :appId path segment)","Wrap SDK calls in scripts with context.getWorkspaceContext / doInWorkspaceContext passing a valid workspace id","Verify the HTTP client (curl, automation, proxy) actually sends the app identifier on the import route","Log context.getWorkspaceId() at the call site to confirm it is set before calling importProject"],"exampleFix":"// before\nawait importProject({ path: filePath })\n// after\nawait context.doInWorkspaceContext(workspaceId, () =>\n  importProject({ path: filePath })\n)","handlingStrategy":"type-guard","validationCode":"if (!context.getWorkspaceId()) {\n  throw new Error(\"importProject requires a workspace context\")\n}\nawait importProject({ path })","typeGuard":"const hasWorkspaceContext = (): boolean =>\n  typeof context.getWorkspaceId() === \"string\" && context.getWorkspaceId()!.length > 0","tryCatchPattern":"try {\n  await importProject({ path })\n} catch (e) {\n  if (String(e.message).includes(\"Could not determine workspace\")) {\n    // re-run inside doInWorkspaceContext with an explicit workspace id\n  }\n}","preventionTips":["Always call importProject inside a workspace-scoped request or doInWorkspaceContext","Propagate the appId through background jobs and workers","Assert workspace context at the start of import scripts"],"tags":["context","workspace","import","missing-context"],"backgroundTag":"missing-workspace-context","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}