Budibase/budibase · error
Invalid tableId: ${tableId}
Error message
Invalid tableId: ${tableId} What it means
fetch(tableId) queries the link view keyed by table ID and rejects any tableId that fails isTableIdOrExternalTableId validation before touching the database. This guards CouchDB range queries from being built with garbage keys that would silently return wrong or empty link results.
Source
Thrown at packages/server/src/sdk/workspace/links/links.ts:13
import { context } from "@budibase/backend-core"
import { isTableIdOrExternalTableId } from "@budibase/shared-core"
import {
DatabaseQueryOpts,
LinkDocument,
LinkDocumentValue,
} from "@budibase/types"
import { ViewName, getQueryIndex } from "../../../db/utils"
export async function fetch(tableId: string): Promise<LinkDocumentValue[]> {
if (!isTableIdOrExternalTableId(tableId)) {
throw new Error(`Invalid tableId: ${tableId}`)
}
const db = context.getWorkspaceDB()
const params: DatabaseQueryOpts = {
startkey: [tableId],
endkey: [tableId, {}],
}
const linkRows = (await db.query(getQueryIndex(ViewName.LINK), params)).rows
return linkRows.map(row => row.value as LinkDocumentValue)
}
export async function fetchWithDocument(
tableId: string
): Promise<LinkDocument[]> {
if (!isTableIdOrExternalTableId(tableId)) {
throw new Error(`Invalid tableId: ${tableId}`)
}
View on GitHub (pinned to a81a902e9a)
Solutions
- Log the tableId and confirm it is a valid Budibase table ID (ta/... format or a valid external table ID)
- Fetch the table via sdk.tables.get first to confirm it exists and use its _id
- Check for undefined IDs caused by unawaited lookups or missing route params upstream
Example fix
// before const links = await links.fetch(table.name) // not an ID // after const links = await links.fetch(table._id!)
Defensive patterns
Strategy: validation
Validate before calling
const isValidTableId = (id?: string) =>
typeof id === "string" && (id.startsWith("ta_") || /^[a-z]+[a-zA-Z0-9_]*\/|[a-f0-9-]{36}/.test(id))
if (!isValidTableId(tableId)) throw new Error(`Refusing to fetch links for invalid tableId: ${tableId}`) Type guard
const isTableId = (id: string | undefined): id is string =>
typeof id === "string" && id.length > 0 && id.startsWith("ta_") Try / catch
try {
const links = await links.fetch(tableId)
} catch (err) {
if (err.message.startsWith("Invalid tableId")) {
return [] // or re-resolve the table ID from the table document
}
throw err
} Prevention
- Always pass table._id, never table names or row IDs
- Resolve IDs from the tables API rather than trusting route params directly
- For external tables, use the ID exactly as returned by the datasource
When it happens
Trigger: Calling sdk.workspace.links.fetch with undefined, an empty string, a non-table document ID (e.g. a datasource or row ID), or a malformed external table ID (e.g. missing the datasource prefix format expected by isTableIdOrExternalTableId).
Common situations: UI code passing a table name instead of its ID; plugins/automations passing row IDs; external (SQL) datasource tables whose IDs include an encoded connector prefix that was mangled before the call.
Related errors
- Error getting status
- Unable to remove doc without a valid _id and _rev.
- Cannot store document without _id field.
- Configuration invalid. Must contain google clientID and clie
- Configuration invalid. Must contain clientID, clientSecret,
AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29).
Data as JSON: /api/errors/a15b646c4b3ea7f2.
Report an issue: GitHub.