hcengineering/platform · error · Error
Cannot import attachment without parent doc: ${docMeta.id}
Error message
Cannot import attachment without parent doc: ${docMeta.id} What it means
importAttachment uploads file bytes and then attaches them to a parent document via AttachedData built from parentMeta. Attachments cannot exist without a parent document, so when parentMeta is undefined the importer refuses to upload rather than creating an orphaned attachment.
Source
Thrown at packages/importer/src/notion/notion.ts:404
notionParentId: dbPage.id,
name: docMeta.name,
notionId: docMeta.notionId,
mimeType: docMeta.mimeType,
size: docMeta.size
}
await importAttachment(client, fileUploader, data, attachment, space, dbPage)
}
async function importAttachment (
client: TxOperations,
fileUploader: FileUploader,
data: Buffer,
docMeta: DocumentMetadata,
space: Ref<Teamspace>,
parentMeta?: DocumentMetadata
): Promise<void> {
if (parentMeta === undefined) {
throw new Error('Cannot import attachment without parent doc: ' + docMeta.id)
}
const file = new File([new Uint8Array(data)], docMeta.name)
await fileUploader.uploadFile(docMeta.id, file)
const attachedData: AttachedData<Attachment> = {
file: docMeta.id as Ref<Blob>,
name: docMeta.name,
lastModified: Date.now(),
type: file.type,
size: file.size
}
await client.addCollection(
attachment.class.Attachment,
space,
parentMeta.id as Ref<Document>,
document.class.Document,View on GitHub (pinned to 63e28dc964)
Solutions
- Resolve the parent DocumentMetadata before calling importAttachment and pass it as parentMeta
- Fix the caller (e.g. importDBAttachment flow) so a missing parent aborts earlier instead of passing undefined
- Skip or defer attachments whose parent page metadata cannot be resolved
- Ensure documentMetaMap is populated with parent pages before processing attachments
Example fix
// before
await importAttachment(client, fileUploader, data, docMeta, space)
// after
const parentMeta = documentMetaMap.get(docMeta.notionParentId)
if (parentMeta !== undefined) {
await importAttachment(client, fileUploader, data, docMeta, space, parentMeta)
} Defensive patterns
Strategy: validation
Validate before calling
if (parentMeta === undefined) {
throw new Error('Skipping attachment ' + docMeta.id + ': no parent document resolved')
}
await importAttachment(client, fileUploader, data, docMeta, space, parentMeta) Type guard
function canAttach(docMeta, parentMeta) {
return parentMeta != null && typeof parentMeta.id === 'string'
} Try / catch
try {
await importAttachment(client, fileUploader, data, docMeta, space, parentMeta)
} catch (err) {
if (err.message.startsWith('Cannot import attachment without parent doc: ')) {
console.warn('Orphan attachment skipped:', docMeta.id)
return
}
throw err
} Prevention
- Resolve and pass parentMeta for every attachment upload
- Abort or defer attachment processing when the parent page lookup fails instead of passing undefined
- Ensure createDBPageWithAttachments completes page creation before attaching files
- Log unresolved notionParentId values to detect gaps in metadata collection
When it happens
Trigger: importAttachment called with parentMeta omitted — e.g. from createDBPageWithAttachments or importDBAttachment when the DB page lookup failed and parent metadata was passed through as undefined.
Common situations: Calling the attachment import API directly without resolving the parent page first; upstream importDBAttachment error paths that pass undefined parentMeta; attachments appearing in the export before/without their parent page metadata.
Related errors
- Teamspace not found for document: ${docMeta.name}
- Importing folder entry is not supported: ${fileMeta.fileName
- DB file not found: ${docMeta.name}
- DB page metadata not found: ${docMeta.name}
- Linked page not found (outside of this import):
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/43513ce4ebaa5345.
Report an issue: GitHub.