{"record":{"id":"7db4ad2ffc33fa65","repo":"Budibase/budibase","slug":"knowledge-base-file-is-missing-object-key","errorCode":null,"errorMessage":"Knowledge base file is missing object key","messagePattern":"Knowledge base file is missing object key","errorType":"http","errorClass":"HTTPError","httpStatus":400,"severity":"error","filePath":"packages/server/src/sdk/workspace/ai/rag/files.ts","lineNumber":327,"sourceCode":"  operationId: string,\n  fileId: string\n): Promise<string> => {\n  const file = await knowledgeBaseSdk.getKnowledgeBaseFileOrThrow(fileId)\n  const fileKnowledgeBaseId = file.knowledgeBaseId\n  if (!fileKnowledgeBaseId) {\n    throw new HTTPError(\"Invalid knowledge base file id\", 400)\n  }\n\n  const knowledgeBaseIds = await getKnowledgeBaseIdsForOperation(\n    agentId,\n    operationId\n  )\n  if (!knowledgeBaseIds.includes(fileKnowledgeBaseId)) {\n    throw new HTTPError(\"File does not belong to this operation\", 404)\n  }\n\n  if (!file.objectStoreKey) {\n    throw new HTTPError(\"Knowledge base file is missing object key\", 400)\n  }\n\n  return await objectStore.getPresignedUrl(\n    ObjectStoreBuckets.APPS,\n    file.objectStoreKey\n  )\n}\n\nconst getKnowledgeBaseIdsForAgent = async (\n  agentId: string\n): Promise<string[]> => {\n  const agent = await agentsSdk.getOrThrow(agentId)\n  return (\n    agent.operations?.flatMap(operation => operation.knowledgeBases || []) || []\n  ).filter(Boolean)\n}\n\nexport const listFilesForAgent = async (","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/ai/rag/files.ts#L309-L345","documentation":"Thrown by getFileUrlForOperation when a knowledge base file record exists but has no objectStoreKey. The objectStoreKey is required to generate a presigned URL in the APPS bucket, so a file without one cannot be downloaded or linked.","triggerScenarios":"Calling getFileUrlForOperation with a fileId whose stored knowledge base file record lacks the objectStoreKey field (e.g. an upload that never completed object-store registration).","commonSituations":"Partially failed file uploads, records created by an older version before objectStoreKey was persisted, or manually inserted/corrupted DB rows.","solutions":["Re-upload the file so a fresh record with a valid objectStoreKey is created","Verify the upload pipeline persists objectStoreKey before the file record is considered ready","Check the file record in the database to confirm objectStoreKey is populated"],"exampleFix":"// before\nconst url = await getFileUrlForOperation({ operationId, fileId })\n// after\nconst file = await knowledgeBaseSdk.getKnowledgeBaseFileOrThrow(fileId)\nif (!file.objectStoreKey) {\n  // re-upload or surface a proper 'file not ready' state to the user\n  throw new Error(`File ${fileId} has no object store key; re-upload required`)\n}\nconst url = await getFileUrlForOperation({ operationId, fileId })","handlingStrategy":"validation","validationCode":"const file = await knowledgeBaseSdk.getKnowledgeBaseFileOrThrow(fileId)\nif (!file.objectStoreKey) throw new Error(`File ${fileId} has no object store key`)","typeGuard":"const hasObjectStoreKey = (f: KnowledgeBaseFile): f is KnowledgeBaseFile & { objectStoreKey: string } => typeof f.objectStoreKey === \"string\" && f.objectStoreKey.length > 0","tryCatchPattern":"try {\n  const url = await getFileUrlForOperation({ operationId, fileId })\n} catch (err) {\n  if (err instanceof HTTPError && err.status === 400) {\n    // treat as 'file not stored' - re-upload or show not-available state\n  } else throw err\n}","preventionTips":["Only expose files to users after objectStoreKey is persisted","Re-upload instead of retrying URL generation for records without a key","Audit for null objectStoreKey after migrations"],"tags":["object-store","missing-field","knowledge-base"],"backgroundTag":"missing-object-store-key","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}