{"record":{"id":"9f33e316d7161996","repo":"Budibase/budibase","slug":"unable-to-retrieve-dev-db-no-workspace-id","errorCode":null,"errorMessage":"Unable to retrieve dev DB - no workspace ID.","messagePattern":"Unable to retrieve dev DB - no workspace ID\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/backend-core/src/context/mainContext.ts","lineNumber":445,"sourceCode":" * This specifically gets the prod workspace ID, if the request\n * contained a development workspace ID, this will get the prod one.\n */\nexport function getProdWorkspaceDB(opts?: any): Database {\n  const workspaceId = getWorkspaceId()\n  if (!workspaceId) {\n    throw new Error(\"Unable to retrieve prod DB - no workspace ID.\")\n  }\n  return getDB(conversions.getProdWorkspaceID(workspaceId), opts)\n}\n\n/**\n * This specifically gets the dev workspace ID, if the request\n * contained a prod workspace ID, this will get the dev one.\n */\nexport function getDevWorkspaceDB(opts?: any): Database {\n  const workspaceId = getWorkspaceId()\n  if (!workspaceId) {\n    throw new Error(\"Unable to retrieve dev DB - no workspace ID.\")\n  }\n  return getDB(conversions.getDevWorkspaceID(workspaceId), opts)\n}\n\nexport function isScim(): boolean {\n  const context = Context.get()\n  const scimCall = context?.isScim\n  return !!scimCall\n}\n\nexport function getCurrentContext(): ContextMap | undefined {\n  try {\n    return Context.get()\n  } catch (e) {\n    return undefined\n  }\n}\n","sourceCodeStart":427,"sourceCodeEnd":463,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/backend-core/src/context/mainContext.ts#L427-L463","documentation":"getDevWorkspaceDB converts the current context workspace ID to its development form and opens that DB. It throws when no workspace ID exists in the ambient context, so the dev DB cannot be resolved.","triggerScenarios":"Calling getDevWorkspaceDB (aliases devDb/developmentDb/dbs) in global-scope endpoints, cron jobs, or any code executed without a workspace-bound context.","commonSituations":"Same as prod variant: missing context middleware, tenant-level code paths, tests that didn't mock workspace context, workers processing messages without workspace metadata.","solutions":["Run the code within a workspace-scoped request or set workspace context explicitly before the call","Use a directly named getDB(...) call when the operation is not workspace-specific","Check that callers propagate the app/workspace ID into background jobs"],"exampleFix":"// before\nconst db = getDevWorkspaceDB()\n// after\nawait withWorkspaceContext(workspaceId, async () => {\n  const db = getDevWorkspaceDB()\n  // ...\n})","handlingStrategy":"validation","validationCode":"import { getWorkspaceId } from \"@budibase/backend-core/context\"\nif (!getWorkspaceId()) {\n  throw new Error(\"dev DB requested outside workspace context\")\n}\nconst db = getDevWorkspaceDB()","typeGuard":"const hasWorkspaceContext = (): boolean => !!getWorkspaceId()","tryCatchPattern":"try {\n  const db = getDevWorkspaceDB()\n} catch (err) {\n  if (err.message.includes(\"no workspace ID\")) {\n    // establish context or use explicit getDB\n  } else throw err\n}","preventionTips":["Same as prod variant: keep dev DB access inside workspace-bound context","Wrap job/queue handlers with context restoration middleware","Prefer explicit getDB in global-scope code"],"tags":["request-context","database-context","missing-id"],"backgroundTag":"missing-workspace-context","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}