{"record":{"id":"311a2bad423da3e5","repo":"Budibase/budibase","slug":"error-importing-documents","errorCode":null,"errorMessage":"Error importing documents","messagePattern":"Error importing documents","errorType":"http","errorClass":"HTTPError","httpStatus":500,"severity":"critical","filePath":"packages/server/src/sdk/workspace/workspaces/import.ts","lineNumber":228,"sourceCode":"        return false\n      }\n      const tableId = getTableIdFromRowId(docId)\n      return tableId ? existingTableIds.has(tableId) : false\n    }\n\n    const filteredUpdate = toUpdate.filter(\n      doc => !isRowOfExistingTable(doc._id)\n    )\n    const filteredDelete = toDelete.filter(\n      doc => !isRowOfExistingTable(doc._id)\n    )\n\n    // now bulk update documents - add new ones, delete old ones and update common ones\n    const updateDocsResult = await workspaceDb.bulkDocs(\n      mergeUpdateAndDeleteDocuments(filteredUpdate, filteredDelete, newMetadata)\n    )\n    if (updateDocsResult.some(r => r.error)) {\n      throw new HTTPError(\"Error importing documents\", 500)\n    }\n\n    await cache.destroy(getWorkspaceMigrationCacheKey(devId))\n    await processMigrations(devId)\n  } finally {\n    await tempDb.destroy()\n  }\n}\n","sourceCodeStart":210,"sourceCodeEnd":237,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/workspaces/import.ts#L210-L237","documentation":"updateWithExport bulk-writes merged documents (new, updated, deleted, metadata) into the workspace DB. If any CouchDB bulkDocs result row contains an error, an HTTPError 500 'Error importing documents' is thrown, leaving the import partially applied (earlier steps are not rolled back by this check).","triggerScenarios":"Any imported document fails validation or conflicts on write — commonly a _rev conflict (doc updated in the target since the export was taken), an invalid doc shape, or a deleted doc whose rev cannot be honored.","commonSituations":"Importing an old export into a workspace that has since changed; concurrent edits in the dev app during import; exported docs carrying revs that don't exist in the target DB.","solutions":["Retake a fresh export of the source app and retry the import","Ensure no concurrent writes to the target workspace during import (perform in a quiet window)","Inspect CouchDB logs / the docs in the export for rev conflicts and remove or re-rev them","Restore the workspace from a backup taken before the failed import"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-check revs against target DB where possible\nfor (const doc of exportedDocs) {\n  if (doc._rev) {\n    const existing = await workspaceDb.tryGet(doc._id)\n    if (!existing && doc._deleted !== true) delete doc._rev // treat as new\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await importToWorkspace(...)\n} catch (e) {\n  if (e?.message === 'Error importing documents') {\n    // restore from backup, take fresh export, retry without concurrent writers\n  } else throw e\n}","preventionTips":["Take a fresh export immediately before import","Ensure no concurrent edits to the target workspace during import","Keep a pre-import backup for rollback"],"tags":["import","bulk-write","conflict","http-500"],"backgroundTag":"bulk-docs-conflict","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}