{"record":{"id":"272af315d967c6b5","repo":"flowable/flowable-engine","slug":"could-not-find-a-batch-with-id-batchid-272af3","errorCode":null,"errorMessage":"Could not find a batch with id '${batchId}'.","messagePattern":"Could not find a batch with id '(.+?)'\\.","errorType":"http","errorClass":"FlowableObjectNotFoundException","httpStatus":404,"severity":"error","filePath":"modules/flowable-rest/src/main/java/org/flowable/rest/service/api/management/BatchResource.java","lineNumber":107,"sourceCode":"\n    @ApiOperation(value = \"Delete a batch\", tags = { \"Batches\" }, nickname = \"deleteBatch\", code = 204)\n    @ApiResponses(value = {\n            @ApiResponse(code = 204, message = \"Indicates the batch was found and has been deleted. Response-body is intentionally empty.\"),\n            @ApiResponse(code = 404, message = \"Indicates the requested batch was not found.\")\n    })\n    @DeleteMapping(\"/management/batches/{batchId}\")\n    @ResponseStatus(HttpStatus.NO_CONTENT)\n    public void deleteJob(@ApiParam(name = \"batchId\") @PathVariable String batchId) {\n        Batch batch = getBatchById(batchId);\n        if (restApiInterceptor != null) {\n            restApiInterceptor.deleteBatch(batch);\n        }\n        \n        try {\n            managementService.deleteBatch(batchId);\n        } catch (FlowableObjectNotFoundException aonfe) {\n            // Re-throw to have consistent error-messaging across REST-api\n            throw new FlowableObjectNotFoundException(\"Could not find a batch with id '\" + batchId + \"'.\", Batch.class);\n        }\n    }\n}\n","sourceCodeStart":89,"sourceCodeEnd":111,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-rest/src/main/java/org/flowable/rest/service/api/management/BatchResource.java#L89-L111","documentation":"DELETE /management/batches/{batchId} calls managementService.deleteBatch; if the underlying service throws FlowableObjectNotFoundException, the resource catches it and re-throws a new FlowableObjectNotFoundException typed to Batch.class with a consistent REST message. It means no batch with that id exists to delete.","triggerScenarios":"DELETE /management/batches/{batchId} with an unknown, already-deleted, or already-completed-and-purged batch id.","commonSituations":"Double-delete (retry after the first delete succeeded); batch finished and removed by cleanup between listing and deleting; stale id cached from a previous run or another database.","solutions":["Check existence first with managementService.createBatchQuery().batchId(batchId).singleResult() and skip the delete when null.","Treat the 404 as idempotent success in the client (delete-then-ignore-not-found).","Verify the id is a batch id and points to the intended database/environment.","If batches vanish quickly, disable/adjust automatic batch cleanup or query before acting."],"exampleFix":"// before\nBatch b = managementService.createBatchQuery().batchId(id).singleResult();\ndeleteBatchUnchecked(id); // 404 on second call\n// after\nBatch b = managementService.createBatchQuery().batchId(id).singleResult();\nif (b != null) { managementService.deleteBatch(id); } // idempotent","handlingStrategy":"validation","validationCode":"Batch batch = managementService.createBatchQuery().batchId(batchId).singleResult();\nif (batch != null) { managementService.deleteBatch(batchId); }","typeGuard":null,"tryCatchPattern":"try { client.deleteBatch(batchId); }\ncatch (FlowableObjectNotFoundException e) { /* already deleted — treat as success for idempotent delete */ }","preventionTips":["Make deletes idempotent: ignore not-found on retry.","Don't cache batch ids across environments/databases.","Query the batch before deleting when the flow may race with cleanup.","Confirm you hold a batch id, not a batch-part or job id."],"tags":["rest-api","flowable","not-found","delete","batch"],"backgroundTag":"record-not-found","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}