{"record":{"id":"111ba26e51357d37","repo":"hcengineering/platform","slug":"couldn-t-find-the-parent-document-meta-with-id","errorCode":null,"errorMessage":"Couldn't find the parent document meta with id: ${parentDocObj.attachedTo}","messagePattern":"Couldn't find the parent document meta with id: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"plugins/controlled-documents/src/docutils.ts","lineNumber":50,"sourceCode":"import documents from './plugin'\nimport { getDocumentId, getFirstRank, TEMPLATE_PREFIX } from './utils'\n\nasync function getParentPath (client: TxOperations, parent: Ref<ProjectDocument>): Promise<Array<Ref<DocumentMeta>>> {\n  const parentDocObj = await client.findOne(documents.class.ProjectDocument, {\n    _id: parent\n  })\n\n  if (parentDocObj === undefined) {\n    console.warn(`Couldn't find the parent project document object with id: ${parent}`)\n    return []\n  }\n\n  const parentMeta = await client.findOne(documents.class.ProjectMeta, {\n    _id: parentDocObj.attachedTo\n  })\n\n  if (parentMeta === undefined) {\n    console.warn(`Couldn't find the parent document meta with id: ${parentDocObj.attachedTo}`)\n    return []\n  }\n\n  return [parentMeta.meta, ...parentMeta.path]\n}\n\nexport async function createControlledDocFromTemplate (\n  client: TxOperations,\n  templateId: Ref<DocumentTemplate> | undefined,\n  documentId: Ref<ControlledDocument>,\n  spec: AttachedData<ControlledDocument>,\n  space: Ref<DocumentSpace>,\n  project: Ref<Project> | undefined,\n  parent: Ref<ProjectDocument> | undefined,\n  docClass: Ref<Class<ControlledDocument>> = documents.class.ControlledDocument\n): Promise<{ seqNumber: number, success: boolean }> {\n  if (templateId == null) {\n    return { seqNumber: -1, success: false }","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/plugins/controlled-documents/src/docutils.ts#L32-L68","documentation":"A controlled document, template, or folder references a parent document via parentDocObj.attachedTo, but no ProjectMeta object exists with that id. getParentPath needs the parent's ProjectMeta to build the breadcrumb path (parent meta plus ancestors). It logs a warning and returns an empty array, degrading gracefully instead of throwing.","triggerScenarios":"Calling createControlledDocMetadata, createDocumentTemplateMetadata, or createNewFolder with a `parent` object whose `attachedTo` is undefined/null, points to a deleted ProjectMeta, or was never created (e.g. parent folder created without its metadata commit).","commonSituations":"Passing a document id instead of the metadata object; the parent was removed by another user concurrently; migrations or partial commits left documents attached to nonexistent meta records.","solutions":["Verify the parent ProjectMeta exists (client.findOne(documents.class.ProjectMeta, { _id: parent.attachedTo })) before creating the child document.","Fix the caller so it passes the metadata object (with correct attachedTo) rather than the raw document.","Check for concurrent deletions or failed parent commits and re-create the missing parent meta.","Handle the empty return value: downstream code building paths should treat [] as 'no parent path' rather than proceeding with invalid assumptions."],"exampleFix":"// before\nawait createControlledDocMetadata(client, { parent: { attachedTo: someDocumentId } })\n// after\nconst parentMeta = await client.findOne(documents.class.ProjectMeta, { _id: someDocumentId })\nif (parentMeta === undefined) throw new Error('parent meta missing')\nawait createControlledDocMetadata(client, { parent: { attachedTo: parentMeta._id } })","handlingStrategy":"validation","validationCode":"const parentMeta = await client.findOne(documents.class.ProjectMeta, { _id: parent.attachedTo })\nif (parentMeta === undefined) throw new Error(`parent meta ${parent.attachedTo} not found`)","typeGuard":"function hasParentMeta(obj: any): obj is { attachedTo: string } {\n  return obj != null && typeof obj.attachedTo === 'string' && obj.attachedTo.length > 0\n}","tryCatchPattern":"const path = await getParentPath(client, parentDocObj)\nif (path.length === 0) {\n  // parent meta missing: treat as top-level or abort\n  return fallbackPath\n}","preventionTips":["Always create the parent ProjectMeta before attaching child documents.","Pass the metadata object, not the raw document, as parent.","Treat an empty returned path as a signal to stop or fall back."],"tags":["controlled-documents","missing-parent","data-integrity"],"backgroundTag":"missing-parent-record","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}