{"record":{"id":"e3f2cc3435f32e78","repo":"Budibase/budibase","slug":"workspace-db-not-found-self-host-users-using-clo","errorCode":null,"errorMessage":"Workspace DB not found - self-host users using cloud don't have workspace DBs","messagePattern":"Workspace DB not found - self-host users using cloud don't have workspace DBs","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/backend-core/src/context/mainContext.ts","lineNumber":419,"sourceCode":"\nexport function getAuditLogsDB(): Database {\n  if (!getTenantId()) {\n    throw new Error(\"No tenant ID found - cannot open audit log DB\")\n  }\n  return getDB(getAuditLogDBName())\n}\n\n/**\n * Gets the workspace database based on whatever the request\n * contained, dev or prod.\n */\nexport function getWorkspaceDB(opts?: any): Database {\n  const workspaceId = getWorkspaceId()\n  if (!workspaceId) {\n    throw new Error(\"Unable to retrieve workspace DB - no workspace ID.\")\n  }\n  if (isSelfHostUsingCloud()) {\n    throw new Error(\n      \"Workspace DB not found - self-host users using cloud don't have workspace DBs\"\n    )\n  }\n  return getDB(workspaceId, opts)\n}\n\n/**\n * 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","sourceCodeStart":401,"sourceCodeEnd":437,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/backend-core/src/context/mainContext.ts#L401-L437","documentation":"getWorkspaceDB resolves the current request's workspace (app) database from request context. If the deployment is self-hosted in 'using cloud' mode, workspace DBs are not provisioned locally, so the function refuses to return one. It signals that the caller is asking for a resource that does not exist in this deployment mode.","triggerScenarios":"Calling getWorkspaceDB (or the db alias) inside a request context whose workspace ID resolves while isSelfHostUsingCloud() is true — i.e. a self-hosted install configured to use Budibase cloud services tries to open any workspace DB.","commonSituations":"Self-hosted environments misconfigured with cloud licensing/account settings; code paths (automations, API handlers) that assume a local app DB exists but run against a self-host-cloud hybrid install.","solutions":["Verify the deployment mode: a self-host install should not run with cloud mode flags; correct SELF_HOSTED / cloud-related env vars and restart","If this is genuinely a cloud-only resource, route the request to the cloud service instead of opening a local workspace DB","Guard calls with isSelfHostUsingCloud() before requesting a workspace DB and use the appropriate API in that mode"],"exampleFix":"// before\nconst db = getWorkspaceDB()\n// after\nif (isSelfHostUsingCloud()) {\n  throw new Error(\"Workspace DBs unavailable in self-host cloud mode\")\n}\nconst db = getWorkspaceDB()","handlingStrategy":"validation","validationCode":"import { isSelfHostUsingCloud } from \"@budibase/backend-core/context\"\nif (isSelfHostUsingCloud()) {\n  // use cloud API instead of local workspace DB\n}\nconst db = getWorkspaceDB()","typeGuard":null,"tryCatchPattern":"try {\n  const db = getWorkspaceDB()\n  // ...\n} catch (err) {\n  if (err.message.includes(\"self-host users using cloud\")) {\n    // fall back to cloud path\n  } else throw err\n}","preventionTips":["Check deployment mode early at startup and branch data-access strategy accordingly","Centralize DB access behind a helper that handles self-host-cloud mode","Document that workspace DB helpers are unavailable in self-host-cloud mode"],"tags":["configuration","self-host","database-context"],"backgroundTag":"workspace-db-unavailable-in-self-host-cloud","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}