Budibase/budibase · error

Unable to retrieve dev DB - no workspace ID.

Error message

Unable to retrieve dev DB - no workspace ID.

What it means

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.

Source

Thrown at packages/backend-core/src/context/mainContext.ts:445

 * This specifically gets the prod workspace ID, if the request
 * contained a development workspace ID, this will get the prod one.
 */
export function getProdWorkspaceDB(opts?: any): Database {
  const workspaceId = getWorkspaceId()
  if (!workspaceId) {
    throw new Error("Unable to retrieve prod DB - no workspace ID.")
  }
  return getDB(conversions.getProdWorkspaceID(workspaceId), opts)
}

/**
 * This specifically gets the dev workspace ID, if the request
 * contained a prod workspace ID, this will get the dev one.
 */
export function getDevWorkspaceDB(opts?: any): Database {
  const workspaceId = getWorkspaceId()
  if (!workspaceId) {
    throw new Error("Unable to retrieve dev DB - no workspace ID.")
  }
  return getDB(conversions.getDevWorkspaceID(workspaceId), opts)
}

export function isScim(): boolean {
  const context = Context.get()
  const scimCall = context?.isScim
  return !!scimCall
}

export function getCurrentContext(): ContextMap | undefined {
  try {
    return Context.get()
  } catch (e) {
    return undefined
  }
}

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Run the code within a workspace-scoped request or set workspace context explicitly before the call
  2. Use a directly named getDB(...) call when the operation is not workspace-specific
  3. Check that callers propagate the app/workspace ID into background jobs

Example fix

// before
const db = getDevWorkspaceDB()
// after
await withWorkspaceContext(workspaceId, async () => {
  const db = getDevWorkspaceDB()
  // ...
})
Defensive patterns

Strategy: validation

Validate before calling

import { getWorkspaceId } from "@budibase/backend-core/context"
if (!getWorkspaceId()) {
  throw new Error("dev DB requested outside workspace context")
}
const db = getDevWorkspaceDB()

Type guard

const hasWorkspaceContext = (): boolean => !!getWorkspaceId()

Try / catch

try {
  const db = getDevWorkspaceDB()
} catch (err) {
  if (err.message.includes("no workspace ID")) {
    // establish context or use explicit getDB
  } else throw err
}

Prevention

When it happens

Trigger: Calling getDevWorkspaceDB (aliases devDb/developmentDb/dbs) in global-scope endpoints, cron jobs, or any code executed without a workspace-bound context.

Common situations: Same as prod variant: missing context middleware, tenant-level code paths, tests that didn't mock workspace context, workers processing messages without workspace metadata.

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/9f33e316d7161996. Report an issue: GitHub.