{"record":{"id":"d375bf206d53f5ac","repo":"flowable/flowable-engine","slug":"could-not-find-a-deployment-with-id-deploymentid-d375bf","errorCode":null,"errorMessage":"Could not find a deployment with id '<deploymentId>'.","messagePattern":"Could not find a deployment with id '<deploymentId>'\\.","errorType":"exception","errorClass":"ActivitiObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/persistence/deploy/DeploymentManager.java","lineNumber":207,"sourceCode":"            deployment.setNew(false);\n            deploy(deployment, null);\n            cachedProcessDefinition = processDefinitionCache.get(processDefinitionId);\n\n            if (cachedProcessDefinition == null) {\n                throw new ActivitiException(\"deployment '\" + deploymentId + \"' didn't put process definition '\" + processDefinitionId + \"' in the cache\");\n            }\n        }\n        return cachedProcessDefinition;\n    }\n\n    public void removeDeployment(String deploymentId, boolean cascade) {\n        DeploymentEntityManager deploymentEntityManager = Context\n                .getCommandContext()\n                .getDeploymentEntityManager();\n\n        DeploymentEntity deployment = deploymentEntityManager.findDeploymentById(deploymentId);\n        if (deployment == null) {\n            throw new ActivitiObjectNotFoundException(\"Could not find a deployment with id '\" + deploymentId + \"'.\", DeploymentEntity.class);\n        }\n\n        // Remove any process definition from the cache\n        List<ProcessDefinition> processDefinitions = new ProcessDefinitionQueryImpl(Context.getCommandContext())\n                .deploymentId(deploymentId)\n                .list();\n\n        FlowableEventDispatcher eventDispatcher = Context.getProcessEngineConfiguration().getEventDispatcher();\n\n        for (ProcessDefinition processDefinition : processDefinitions) {\n\n            // Since all process definitions are deleted by a single query, we should dispatch the events in this loop\n            if (eventDispatcher.isEnabled()) {\n                eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(\n                        FlowableEngineEventType.ENTITY_DELETED, processDefinition),\n                        EngineConfigurationConstants.KEY_PROCESS_ENGINE_CONFIG);\n            }\n        }","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/persistence/deploy/DeploymentManager.java#L189-L225","documentation":"ActivitiObjectNotFoundException thrown by DeploymentManager.removeDeployment when the deployment id passed to RepositoryService.deleteDeployment does not exist. The engine looks up the DeploymentEntity first; null triggers this error before any cascade deletion begins, so nothing is removed.","triggerScenarios":"Calling repositoryService.deleteDeployment(deploymentId) or deleteDeployment(deploymentId, cascade) with an id that was never created, already deleted, or belongs to another database/tenant.","commonSituations":"Deleting the same deployment twice, ids from a different environment's database, truncated ids from logs, or cleanup scripts running against the wrong schema.","solutions":["Check existence first: repositoryService.createDeploymentQuery().deploymentId(id).singleResult() != null","Skip deletion (or log-and-continue) when the deployment is already absent — the end state (not deployed) is already achieved","List valid deployments via repositoryService.createDeploymentQuery().list() to find the correct id","Verify the delete runs against the same database the deployment was made in"],"exampleFix":"// before\nrepositoryService.deleteDeployment(deploymentId, true); // throws if already gone\n// after\nif (repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult() != null) {\n    repositoryService.deleteDeployment(deploymentId, true);\n}","handlingStrategy":"validation","validationCode":"if (repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult() == null) {\n    return; // already deleted — treat delete as idempotent\n}","typeGuard":null,"tryCatchPattern":"try {\n    repositoryService.deleteDeployment(deploymentId, true);\n} catch (ActivitiObjectNotFoundException e) {\n    log.info(\"Deployment {} already removed\", deploymentId);\n}","preventionTips":["Treat deleteDeployment as non-idempotent; check existence first or catch the exception","Never reuse ids copied from logs or other environments","Run cleanup against a verified datasource"],"tags":["deployment","not-found","delete","idempotency"],"backgroundTag":"resource-not-found","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T16:30:33.424Z"}