{"record":{"id":"7d6f0d27856f8334","repo":"flowable/flowable-engine","slug":"variable-name-is-already-present-on-task-t-7d6f0d","errorCode":null,"errorMessage":"Variable '${name}' is already present on task '${task.getId()}'.","messagePattern":"Variable '(.+?)' is already present on task '(.+?)'\\.","errorType":"http","errorClass":"FlowableException","httpStatus":500,"severity":"error","filePath":"modules/flowable-rest/src/main/java/org/flowable/rest/service/api/runtime/task/TaskVariableBaseResource.java","lineNumber":225,"sourceCode":"\n        // Figure out scope, revert to local is omitted\n        RestVariableScope scope = restVariable.getVariableScope();\n        if (scope == null) {\n            scope = RestVariableScope.LOCAL;\n        }\n\n        Object actualVariableValue = restResponseFactory.getVariableValue(restVariable);\n        setVariable(task, restVariable.getName(), actualVariableValue, scope, isNew);\n\n        return getVariableFromRequestWithoutAccessCheck(task, restVariable.getName(), scope.name(), false);\n    }\n\n    protected void setVariable(Task task, String name, Object value, RestVariableScope scope, boolean isNew) {\n        // Create can only be done on new variables. Existing variables should\n        // be updated using PUT\n        boolean hasVariable = hasVariableOnScope(task, name, scope);\n        if (isNew && hasVariable) {\n            throw new FlowableException(\"Variable '\" + name + \"' is already present on task '\" + task.getId() + \"'.\");\n        }\n\n        if (!isNew && !hasVariable) {\n            throw new FlowableObjectNotFoundException(\"Task '\" + task.getId() + \"' does not have a variable with name: '\" + name + \"'.\", null);\n        }\n\n        if (restApiInterceptor != null) {\n            if (isNew) {\n                restApiInterceptor.createTaskVariables(task, Collections.singletonMap(name, value), scope);\n            } else {\n                restApiInterceptor.updateTaskVariables(task, Collections.singletonMap(name, value), scope);\n            }\n        }\n\n        if (scope == RestVariableScope.LOCAL) {\n            taskService.setVariableLocal(task.getId(), name, value);\n        } else {\n            if (task.getExecutionId() != null) {","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-rest/src/main/java/org/flowable/rest/service/api/runtime/task/TaskVariableBaseResource.java#L207-L243","documentation":"REST create/update conflict in TaskVariableBaseResource.setVariable: a variable with the same name already exists on the task while a create operation was requested, so the existing variable must be updated instead.","triggerScenarios":"POST /runtime/tasks/{taskId}/variables with a body whose variable name already exists in the task's local (or chosen) scope. In setVariable(), isNew=true and hasVariableOnScope(task, name, scope) returns true.","commonSituations":"Re-running a script that creates variables; concurrent requests creating the same variable; confusing POST (create) with PUT (update) semantics; the variable exists locally while the client assumed global scope or vice versa.","solutions":["Use PUT /runtime/tasks/{taskId}/variables/{variableName} to update the existing variable instead of POST","Delete the variable first (DELETE endpoint) if you need to recreate it","Check existing variables with GET /runtime/tasks/{taskId}/variables before creating"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const existing = await api.get(`/runtime/tasks/${taskId}/variables`); if (existing.data.some(v => v.name === name && v.variableScope === scope)) { /* update via PUT instead */ }","typeGuard":null,"tryCatchPattern":"try { await api.post(`/runtime/tasks/${taskId}/variables`, body); } catch (e) { if (e.response && e.response.status === 409) { await api.put(`/runtime/tasks/${taskId}/variables/${name}`, body); } else { throw e; } }","preventionTips":["GET existing variables before POST","Remember POST=create, PUT=update semantics","Handle concurrent creators with a unique-name discipline"],"tags":["rest-api","conflict","duplicate"],"backgroundTag":"file-already-exists","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"}