{"record":{"id":"366b78fbebb16229","repo":"hcengineering/platform","slug":"couldn-t-find-the-parent-project-document-object-w","errorCode":null,"errorMessage":"Couldn't find the parent project document object with id: ${parent}","messagePattern":"Couldn't find the parent project document object with id: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"plugins/controlled-documents/src/docutils.ts","lineNumber":41,"sourceCode":"  type DocumentSpace,\n  type DocumentTemplate,\n  type HierarchyDocument,\n  type Project,\n  type ProjectDocument,\n  DocumentState\n} from './types'\nimport { makeRank } from '@hcengineering/rank'\n\nimport 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,","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/plugins/controlled-documents/src/docutils.ts#L23-L59","documentation":"getParentPath in controlled-documents resolves the breadcrumb/path of parent DocumentMeta objects for a parent ProjectDocument. If client.findOne on documents.class.ProjectDocument finds no object for the given parent Ref, it warns \"Couldn't find the parent project document object with id: <parent>\" and returns []. Callers (createControlledDocMetadata, createDocumentTemplateMetadata, createNewFolder) then proceed with an empty path, producing documents with missing/incorrect hierarchy metadata.","triggerScenarios":"Called with a parent Ref pointing to a ProjectDocument that does not exist in the DB - stale/deleted reference, wrong Ref passed, wrong workspace/connection, or the parent was not yet created when the caller ran.","commonSituations":"Passing an ID from another workspace or a removed project document; race where a folder/document is created before its parent commit is visible; copy-pasted or hardcoded Refs in tests/scripts; parent deleted after child creation started.","solutions":["Verify the parent Ref is valid and the ProjectDocument exists (query it in the same client/workspace) before calling createNewFolder/createControlledDocMetadata.","Create the parent document first and use its returned _id as parent.","Check for deletions: ensure the parent was not removed between obtaining the Ref and the call.","Confirm you are connected to the correct workspace - findOne silently misses objects outside it."],"exampleFix":"// before\nawait createNewFolder(client, someParentRef, name) // someParentRef may be stale\n// after\nconst parent = await client.findOne(documents.class.ProjectDocument, { _id: someParentRef })\nif (parent === undefined) throw new Error(`Parent ${someParentRef} not found`) // fail fast instead of empty path\nawait createNewFolder(client, someParentRef, name)","handlingStrategy":"validation","validationCode":"// Verify the parent exists before building metadata/folders\nconst parentDoc = await client.findOne(documents.class.ProjectDocument, { _id: parent })\nif (parentDoc === undefined) {\n  throw new Error(`Parent project document ${parent} does not exist in this workspace`)\n}\n","typeGuard":"function isRef<T extends Doc> (value: unknown): value is Ref<T> {\n  return typeof value === 'string' && value.length > 0\n}\n","tryCatchPattern":"try {\n  const path = await getParentPath(client, parent)\n  if (path.length === 0) throw new Error('Parent path empty - parent not found')\n} catch (err) {\n  console.error('Cannot resolve parent hierarchy', err)\n}\n","preventionTips":["Create parent documents before children and use returned _ids.","Never hardcode or copy Refs across workspaces/tests.","Handle deletions of parents that would orphan child creation.","Confirm the client is bound to the correct workspace before lookups."],"tags":["controlled-documents","missing-document","hierarchy","data-integrity"],"backgroundTag":"parent-document-not-found","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}