{"record":{"id":"7529f4a62228588b","repo":"hcengineering/platform","slug":"unable-to-find-just-created-drawing","errorCode":null,"errorMessage":"Unable to find just created drawing","messagePattern":"Unable to find just created drawing","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/attachment-resources/src/components/AttachmentPreviewPopup.svelte","lineNumber":56,"sourceCode":"          createdOn: SortingOrder.Descending\n        },\n        limit: 1\n      }\n    )\n\n    return Array.from(drawings ?? [])\n  }\n\n  async function createDrawing (data: DrawingData): Promise<DrawingData> {\n    const client = getClient()\n    const newId = await client.createDoc(attachment.class.Drawing, value.space, {\n      parent: value.file,\n      parentClass: core.class.Blob,\n      content: data.content\n    })\n    const newDrawing = await client.findOne(attachment.class.Drawing, { _id: newId })\n    if (newDrawing === undefined) {\n      throw new Error('Unable to find just created drawing')\n    }\n    return newDrawing\n  }\n</script>\n\n<FilePreviewPopup\n  file={value.file}\n  name={value.name}\n  metadata={value.metadata}\n  contentType={value.type}\n  props={{\n    drawingAvailable,\n    loadDrawings,\n    createDrawing\n  }}\n  {fullSize}\n  {showIcon}\n  on:open","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/plugins/attachment-resources/src/components/AttachmentPreviewPopup.svelte#L38-L74","documentation":"AttachmentPreviewPopup.svelte creates a Drawing blob, then immediately findOne's the Drawing attachment by the new id; if the query returns undefined it throws 'Unable to find just created drawing'. This indicates the just-created document was not visible to the client query — usually a client-side index/replication lag or the creation silently failing while still returning an id.","triggerScenarios":"client.findOne(attachment.class.Drawing, { _id: newId }) runs before the newly created object has propagated to the client's query results (offline/sync lag), or the underlying blob/content creation partially failed so no Drawing was persisted despite newId being returned.","commonSituations":"Slow or offline networks with the collaborative backend, large workspaces where the initial query window hasn't loaded the new object, or transient backend errors during createDoc.","solutions":["Retry the findOne briefly (poll a few times with a small delay) before concluding the object is missing.","Check the network/sync status — ensure the client is connected and replication caught up after createDoc.","Verify the createDoc call for the drawing blob actually succeeded (no swallowed errors) before querying.","Await the creation promise chain fully (e.g. await apply/commit of the transaction) before querying."],"exampleFix":"// before\nconst newDrawing = await client.findOne(attachment.class.Drawing, { _id: newId })\nif (newDrawing === undefined) {\n  throw new Error('Unable to find just created drawing')\n}\n// after\nlet newDrawing: Drawing | undefined\nfor (let i = 0; i < 5 && newDrawing === undefined; i++) {\n  newDrawing = await client.findOne(attachment.class.Drawing, { _id: newId })\n  if (newDrawing === undefined) await new Promise(r => setTimeout(r, 200))\n}\nif (newDrawing === undefined) throw new Error('Unable to find just created drawing')","handlingStrategy":"retry","validationCode":"// Poll briefly for the just-created document before failing:\nlet drawing = await client.findOne(attachment.class.Drawing, { _id: newId })\nfor (let i = 0; i < 5 && drawing === undefined; i++) {\n  await new Promise(r => setTimeout(r, 200))\n  drawing = await client.findOne(attachment.class.Drawing, { _id: newId })\n}","typeGuard":"function isDrawing(doc: any | undefined): doc is Drawing {\n  return doc !== undefined && typeof (doc as Drawing)._id === 'string'\n}","tryCatchPattern":"try {\n  return await createAndGetDrawing(data)\n} catch (err) {\n  if (err instanceof Error && err.message === 'Unable to find just created drawing') {\n    showNotification('The drawing could not be loaded. Check your connection and try again.')\n    return null\n  }\n  throw err\n}","preventionTips":["Ensure the client is fully connected and synced before creating drawings.","Await the full transaction/commit before querying the new object.","Poll with a short backoff instead of a single immediate findOne.","Check createDoc errors are not silently swallowed upstream."],"tags":["race-condition","sync-lag","ui","drawing"],"backgroundTag":"created-document-not-found","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}