{"record":{"id":"e14e79186324710c","repo":"flowable/flowable-engine","slug":"historic-variable-instance-could-not-be-found","errorCode":null,"errorMessage":"Historic variable instance '' could not be found.","messagePattern":"Historic variable instance '' could not be found\\.","errorType":"http","errorClass":"FlowableObjectNotFoundException","httpStatus":404,"severity":"error","filePath":"modules/flowable-rest/src/main/java/org/flowable/rest/service/api/history/HistoricVariableInstanceDataResource.java","lineNumber":97,"sourceCode":"                result = buffer.toByteArray();\n                response.setContentType(\"application/x-java-serialized-object\");\n\n            } else {\n                throw new FlowableObjectNotFoundException(\"The variable does not have a binary data stream.\", null);\n            }\n            return result;\n\n        } catch (IOException ioe) {\n            // Re-throw IOException\n            throw new FlowableException(\"Unexpected exception getting variable data\", ioe);\n        }\n    }\n\n    public RestVariable getVariableFromRequest(boolean includeBinary, String varInstanceId) {\n        HistoricVariableInstance varObject = historyService.createHistoricVariableInstanceQuery().id(varInstanceId).singleResult();\n\n        if (varObject == null) {\n            throw new FlowableObjectNotFoundException(\"Historic variable instance '\" + varInstanceId + \"' could not be found.\", VariableInstanceEntity.class);\n        } else {\n            \n            if (restApiInterceptor != null) {\n                restApiInterceptor.accessHistoryVariableInfoById(varObject);\n            }\n            \n            return restResponseFactory.createRestVariable(varObject.getVariableName(), varObject.getValue(), null, varInstanceId, RestResponseFactory.VARIABLE_HISTORY_VARINSTANCE, includeBinary);\n        }\n    }\n}\n","sourceCodeStart":79,"sourceCodeEnd":108,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-rest/src/main/java/org/flowable/rest/service/api/history/HistoricVariableInstanceDataResource.java#L79-L108","documentation":"Flowable's history REST API looks up a historic variable instance by its id via historyService.createHistoricVariableInstanceQuery().id(varInstanceId). When the query returns no result, getVariableFromRequest throws FlowableObjectNotFoundException. This means no historic variable instance exists in the ACT_HI_VARINST table with the supplied id.","triggerScenarios":"GET /history/historic-variable-instances/{variableInstanceId} (with or without ?includeBinary=true, or the /data sub-resource) where the variableInstanceId does not match any row in the historic variable instance table.","commonSituations":"Using a runtime variable id instead of a historic variable instance id; referencing a variable whose history level did not record variables (history level 'none'); data purged or cleaned by history cleanup jobs; typo'd or truncated id copied from logs; variable from a different Flowable database/tenant.","solutions":["Verify the variableInstanceId against the ACT_HI_VARINST table (SELECT * FROM ACT_HI_VARINST WHERE ID_ = '<id>') or by listing GET /history/historic-variable-instances.","Check the process engine's history level (e.g. 'audit' or 'full'); at level 'none' variables are not recorded in history, so re-run the process with a higher history level.","Confirm you are querying the same database/schema and tenant the process ran in.","Ensure history cleanup (flowable.history-cleaning settings) has not removed the instance."],"exampleFix":"// before: guessing the id\nRestVariable v = client.get(\"/history/historic-variable-instances/1234/data\");\n// after: fetch ids from the history query first\nList<HistoricVariableInstance> vars = historyService.createHistoricVariableInstanceQuery()\n    .processInstanceId(pid).list();\nvars.stream()\n    .filter(v -> \"orderTotal\".equals(v.getVariableName()))\n    .findFirst()\n    .ifPresent(v -> client.get(\"/history/historic-variable-instances/\" + v.getId() + \"/data\"));","handlingStrategy":"try-catch","validationCode":"boolean exists = !client.list(\"/history/historic-variable-instances?variableInstanceId=\" + id).isEmpty();","typeGuard":null,"tryCatchPattern":"try {\n    RestVariable v = client.get(\"/history/historic-variable-instances/\" + id + \"/data\");\n} catch (HttpClientErrorException e) {\n    if (e.getStatusCode() == HttpStatus.NOT_FOUND) {\n        log.warn(\"Historic variable instance {} not found (purged or wrong id)\", id);\n    } else throw e;\n}","preventionTips":["Resolve variable instance ids via the historic-variable-instances query API rather than hardcoding.","Set history level to audit/full when variable history is required.","Account for history cleanup retention windows when reading old data."],"tags":["rest-api","history","not-found","flowable"],"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-18T11:17:12.947Z"}