{"record":{"id":"13a8a0d7ba1549c1","repo":"appwrite/appwrite","slug":"deployment-not-found-13a8a0","errorCode":"deployment_not_found","errorMessage":"Deployment not found. Create a deployment before trying to execute a function","messagePattern":"Deployment not found\\. Create a deployment before trying to execute a function","errorType":"exception","errorClass":"Appwrite\\Extend\\Exception","httpStatus":404,"severity":"error","filePath":"src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php","lineNumber":195,"sourceCode":"        if ($function->isEmpty() || (!$function->getAttribute('enabled') && !$isAPIKey && !$isPrivilegedUser)) {\n            throw new Exception(Exception::FUNCTION_NOT_FOUND);\n        }\n\n        $version = $function->getAttribute('version', 'v2');\n        $runtimes = Config::getParam($version === 'v2' ? 'runtimes-v2' : 'runtimes', []);\n\n        $spec = Config::getParam('specifications')[$function->getAttribute('runtimeSpecification', APP_COMPUTE_SPECIFICATION_DEFAULT)];\n\n        $runtime = (isset($runtimes[$function->getAttribute('runtime', '')])) ? $runtimes[$function->getAttribute('runtime', '')] : null;\n\n        if (\\is_null($runtime)) {\n            throw new Exception(Exception::FUNCTION_RUNTIME_UNSUPPORTED, 'Runtime \"' . $function->getAttribute('runtime', '') . '\" is not supported');\n        }\n\n        $deployment = $authorization->skip(fn () => $dbForProject->getDocument('deployments', $function->getAttribute('deploymentId', '')));\n\n        if ($deployment->getAttribute('resourceId') !== $function->getId()) {\n            throw new Exception(Exception::DEPLOYMENT_NOT_FOUND, 'Deployment not found. Create a deployment before trying to execute a function');\n        }\n\n        if ($deployment->isEmpty()) {\n            throw new Exception(Exception::DEPLOYMENT_NOT_FOUND, 'Deployment not found. Create a deployment before trying to execute a function');\n        }\n\n        if ($deployment->getAttribute('status') !== 'ready') {\n            throw new Exception(Exception::BUILD_NOT_READY);\n        }\n\n        if (!$authorization->isValid(new Input('execute', $function->getAttribute('execute')))) { // Check if user has write access to execute function\n            throw new Exception(Exception::USER_UNAUTHORIZED, $authorization->getDescription());\n        }\n\n        $jwt = ''; // initialize\n        if (!$user->isEmpty()) { // If userId exists, generate a JWT for function\n            $sessions = $user->getAttribute('sessions', []);\n            $current = new Document();","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/appwrite/appwrite/blob/ed02ca372a42f39ad522bd44c67bd6ad98adb9fd/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php#L177-L213","documentation":"Executing a function requires an active deployment that belongs to it; this check compares deployment.resourceId to the function ID. In practice it fires when the function has no deploymentId at all (never deployed): the empty document's resourceId is null, which never equals the function ID — and note this check runs before the isEmpty check below it, so most 'never deployed' cases land on this exact line.","triggerScenarios":"POST execution on a freshly created function before any deployment exists; all of a function's deployments deleted so none is active; deploymentId referencing another function's deployment.","commonSituations":"CI creating a function and executing it without a deploy step; test scaffolding that skips deployment; scripts assuming a function ships with a default deployment.","solutions":["Create a deployment first (upload, template, or VCS) and wait for its build to finish","If deployments exist, activate one: PATCH /v1/functions/:functionId with the deploymentId","Re-run the execution only after the active deployment reports 'ready'","In automation, insert a deploy-and-wait step between function creation and execution"],"exampleFix":"// before\nawait functions.create({ functionId, name: 'hello', runtime: 'node-22' });\nawait functions.createExecution({ functionId }); // no deployment yet\n\n// after\nawait functions.create({ functionId, name: 'hello', runtime: 'node-22' });\nawait functions.createDeployment({\n  functionId,\n  code: InputFile.fromBlob(new Blob(['console.log(1)']), 'index.js'),\n  activate: true,\n});\n// wait until getDeployment().status === 'ready', then execute\nawait functions.createExecution({ functionId });","handlingStrategy":"validation","validationCode":"const fn = await functions.get({ functionId });\nif (!fn.deploymentId) {\n  throw new Error('Function has no active deployment — create one before executing');\n}\nconst dep = await functions.getDeployment({ functionId, deploymentId: fn.deploymentId });\nif (dep.status !== 'ready') {\n  throw new Error(`Deployment not ready (status: ${dep.status})`);\n}\nawait functions.createExecution({ functionId });","typeGuard":"function isExecutable(fn: { deploymentId?: string }, dep: { status?: string } | null): boolean {\n  return typeof fn.deploymentId === 'string' && fn.deploymentId.length > 0 && dep?.status === 'ready';\n}","tryCatchPattern":"try {\n  await functions.createExecution({ functionId });\n} catch (e) {\n  if (e?.code === 'deployment_not_found') {\n    // Create + activate a deployment, wait for 'ready', then retry.\n  }\n  throw e;\n}","preventionTips":["Always include a deploy-and-wait step between function creation and execution in pipelines","Create deployments with activate: true so readiness implies executability"],"tags":["appwrite","functions","executions","deployments","not-found"],"backgroundTag":"missing-prerequisite-resource","analyzedSha":"ed02ca372a42f39ad522bd44c67bd6ad98adb9fd","analyzedAt":"2026-08-18T21:34:56.994Z","contentChangedAt":"2026-08-18T21:34:56.994Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}