Budibase/budibase · error

Unable to retrieve prod DB - no workspace ID.

Error message

Unable to retrieve prod DB - no workspace ID.

What it means

getProdWorkspaceDB converts the current context workspace ID to its production form and opens that DB. It throws when the ambient request context contains no workspace ID at all, because there is nothing to convert or open.

Source

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

  if (!workspaceId) {
    throw new Error("Unable to retrieve workspace DB - no workspace ID.")
  }
  if (isSelfHostUsingCloud()) {
    throw new Error(
      "Workspace DB not found - self-host users using cloud don't have workspace DBs"
    )
  }
  return getDB(workspaceId, opts)
}

/**
 * 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()

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Ensure the code path runs inside a request with a workspace ID (app id header/url param) and that context middleware ran
  2. If the code is genuinely workspace-agnostic, use getDB with an explicit DB name instead of context helpers
  3. In scripts/workers, explicitly establish context with the target workspace ID before calling

Example fix

// before
const db = getProdWorkspaceDB()
// after
const workspaceId = getWorkspaceId()
if (!workspaceId) {
  throw new Error("No workspace in context; pass an explicit DB name")
}
const db = getProdWorkspaceDB()
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

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

Try / catch

try {
  const db = getProdWorkspaceDB()
} catch (err) {
  if (err.message.includes("no workspace ID")) {
    // fall back to explicit getDB(name) or return 400 to caller
  } else throw err
}

Prevention

When it happens

Trigger: Calling getProdWorkspaceDB (aliases prodDb/database/dbs/productionDb) outside a workspace-scoped request — e.g. in global/tenant-only endpoints, background jobs, or tests where setWorkspaceId/context was never established.

Common situations: Middleware not populating workspace context (missing app ID header/path), calling prod DB helpers from tenant-level code (users, auth, global config), background tasks that lose the request context.

Related errors


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