Budibase/budibase · error · HTTPError
Project import could not remap datasource for query '${doc._
Error message
Project import could not remap datasource for query '${doc._id}'. What it means
During a project (workspace backup) import, every QUERY document must have its datasourceId remapped to the newly generated datasource ID via the idMap. This error is thrown when a query references a datasourceId that is missing from the import or has no mapping in idMap, meaning the parent datasource was not imported or remapped before the query. The import aborts with HTTP 400 because a query without a valid datasource cannot function.
Source
Thrown at packages/server/src/sdk/workspace/projects/backups/imports.ts:614
const generateImportedId = (
resourceType: ResourceType,
doc: AnyDocument,
idMap: Map<string, string>
) => {
switch (resourceType) {
case ResourceType.AGENT:
return docIds.generateAgentID()
case ResourceType.DATASOURCE:
return generateDatasourceID({
plus: !!doc._id?.startsWith(prefixed(DocumentType.DATASOURCE_PLUS)),
})
case ResourceType.TABLE:
return generateTableID()
case ResourceType.QUERY: {
const datasourceId = doc.datasourceId && idMap.get(doc.datasourceId)
if (!datasourceId) {
throw new HTTPError(
`Project import could not remap datasource for query '${doc._id}'.`,
400
)
}
return generateQueryID(datasourceId)
}
case ResourceType.AUTOMATION:
return generateAutomationID()
case ResourceType.ROW_ACTION: {
const tableId = idMap.get(extractTableIdFromRowActionsID(doc._id!))
if (!tableId) {
throw new HTTPError(
`Project import could not remap table for row actions '${doc._id}'.`,
400
)
}
return generateRowActionsID(tableId)
}View on GitHub (pinned to a81a902e9a)
Solutions
- Ensure the export package includes every datasource document referenced by queries (check manifest.resourcesByType counts).
- Re-export the project from a healthy workspace rather than hand-assembling the package.
- Check the import logs for earlier failures on datasource documents that prevented their ID mapping.
- If intentionally dropping datasources, also drop dependent queries from the package.
Example fix
// before (package json missing datasource doc for query)
{ "queries": [{ "_id": "query_def1", "datasourceId": "datasource_missing" }] }
// after (include the datasource so idMap can remap)
{ "datasources": [{ "_id": "datasource_missing" }], "queries": [{ "_id": "query_def1", "datasourceId": "datasource_missing" }] } Defensive patterns
Strategy: validation
Validate before calling
const dsIds = new Set(docs.filter(d => d.type === ResourceType.DATASOURCE).map(d => d._id))
for (const q of docs.filter(d => d.type === ResourceType.QUERY)) {
if (!q.datasourceId || !dsIds.has(q.datasourceId)) throw new Error(`Query ${q._id} references missing datasource`)
} Type guard
const hasDatasource = (q: Query): q is Query & { datasourceId: string } =>
typeof q.datasourceId === "string" && q.datasourceId.length > 0 Try / catch
try {
await importProjectPackage(file)
} catch (err) {
if (err instanceof HTTPError && err.status === 400 && err.message.includes("could not remap datasource")) {
// surface which query doc failed: parse id from err.message
}
throw err
} Prevention
- Always export via Budibase's own export tooling, never hand-assemble packages
- Verify manifest.resourcesByType datasource counts match the datasources referenced by queries
- Re-download exports if the archive size looks wrong
When it happens
Trigger: Importing a project export where a query doc's datasourceId is undefined or idMap.get(doc.datasourceId) returns undefined — e.g. the export contains a query but not its datasource, the datasource doc failed to import earlier, or the manifest resourcesByType omits the datasource type.
Common situations: Hand-edited or partially truncated export files; exports produced by older/broken export tooling that skipped datasource docs; third-party tooling generating project packages that reference datasources not included in the package.
Related errors
- Project import could not remap table for row actions '${doc.
- Project import does not support resource type '${resourceTyp
- Project package manifest is invalid.
- Supplied file is not a Project package.
- Unsupported Project package format version '${manifest.forma
AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29).
Data as JSON: /api/errors/45a86678a05eb162.
Report an issue: GitHub.