{"record":{"id":"a6873abebebe3018","repo":"Budibase/budibase","slug":"unable-to-retrieve-workspace-metadata-for-import","errorCode":null,"errorMessage":"Unable to retrieve workspace metadata for import - ${err.message}","messagePattern":"Unable to retrieve workspace metadata for import - (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/server/src/sdk/workspace/workspaces/import.ts","lineNumber":58,"sourceCode":"    const [tempMetadata, workspaceMetadata] = await Promise.all([\n      tempDb.get<Workspace>(docId),\n      workspaceDb.get<Workspace>(docId),\n    ])\n    return {\n      ...workspaceMetadata,\n      automationErrors: undefined,\n      theme: tempMetadata.theme,\n      customTheme: tempMetadata.customTheme,\n      snippets: tempMetadata.snippets,\n      features: tempMetadata.features,\n      icon: tempMetadata.icon,\n      navigation: tempMetadata.navigation,\n      scripts: tempMetadata.scripts,\n      type: tempMetadata.type,\n      version: tempMetadata.version,\n    }\n  } catch (err: any) {\n    throw new Error(\n      `Unable to retrieve workspace metadata for import - ${err.message}`\n    )\n  }\n}\n\nfunction mergeUpdateAndDeleteDocuments(\n  updateDocs: Document[],\n  deleteDocs: Document[],\n  metadata: Workspace\n) {\n  // compress the documents to create and to delete (if same ID, then just update the rev)\n  const finalToDelete = []\n  for (let deleteDoc of deleteDocs) {\n    const found = updateDocs.find(doc => doc._id === deleteDoc._id)\n    if (found) {\n      found._rev = deleteDoc._rev\n    } else {\n      finalToDelete.push(deleteDoc)","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/workspaces/import.ts#L40-L76","documentation":"getNewWorkspaceMetadata reads the workspace metadata doc (docId WORKSPACE_METADATA) from both the temporary import DB and the target workspace DB. If either read fails (missing doc, DB unavailable, malformed export), the original error is wrapped in a plain Error prefixed 'Unable to retrieve workspace metadata for import'.","triggerScenarios":"Calling importToWorkspace/newMetadata with an export whose temp DB lacks a valid workspace metadata doc, or when the target workspace DB cannot return its metadata doc (e.g. importing into a corrupt or non-workspace DB).","commonSituations":"Uploading a truncated/corrupted app export file; importing an export from an incompatible Budibase version; target workspace DB was deleted or never initialized; file path points to the wrong artifact.","solutions":["Re-export the app and confirm the export contains the workspace metadata doc","Verify the target workspace exists and its DB has a valid metadata doc before importing","Check the wrapped err.message in the error text to identify the root cause (404 vs connection)","Confirm export/import compatibility between Budibase versions"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const tempMetadata = await tempDb.tryGet(DocumentType.WORKSPACE_METADATA)\nconst targetMetadata = await workspaceDb.tryGet(DocumentType.WORKSPACE_METADATA)\nif (!tempMetadata || !targetMetadata) {\n  throw new Error('Export or target workspace is missing workspace metadata doc')\n}","typeGuard":"function isWorkspaceMetadata(doc) {\n  return !!doc && typeof doc === 'object' && !!doc._id && doc._id.startsWith('workspace_meta')\n}","tryCatchPattern":"try {\n  await importToWorkspace(...)\n} catch (e) {\n  if (e?.message?.startsWith('Unable to retrieve workspace metadata for import')) {\n    // inspect inner message; re-export or verify target workspace\n  } else throw e\n}","preventionTips":["Validate export archives contain the workspace metadata doc before importing","Re-export from a compatible Budibase version","Verify the target workspace DB is healthy before import"],"tags":["import","workspace-metadata","io"],"backgroundTag":"workspace-import-failed","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}