flowable-engine icon indicating copy to clipboard operation
flowable-engine copied to clipboard

Changing assignee in TaskListener is ok in runtime but out-of-date in history

Open verheyenkoen opened this issue 2 years ago • 0 comments

Describe the bug I wrote a custom Java TaskListener that updates the assignee of a user task in certain cases (using delegateTask.setAssignee(...)). After execution of the listener (at the point that the task can be performed) I can see in the task runtime (GET runtime/tasks/{taskId}) that the assignee has changed, but in the task history (GET history/historic-task-instances/{taskId}) it hasn't. This corresponds with what is in the database: table act_ru_task holds the correct value while act_hi_taskinst holds the old value. Also in the admin interface, you see the old assignee in the task list and the tasks of a process instance, but if you go to the task detail page, the updated value is shown.

I've tried to attach the task listener both on the "assignment" and the "create" event of of the task with same result.

Expected behavior I guess task runtime and history should be in synch at all times, like it is for variables or other entity types. Persisting the assignee to act_hi_taskinst as well as act_ru_task after the TaskListener execution should fix this problem.

Code This is the code of my TaskListener bean:

@Override
public void notify(DelegateTask task) {
    String newAssignee = (String) task.getVariable("assignee_override");
    if (StringUtils.hasText(newAssignee)) {
        String previousAssignee = task.getAssignee();
        task.setAssignee(newAssignee);

        LOG.info("Changed assignee of task " + task.getId() + " of type " +
                task.getTaskDefinitionKey() + " from '" + previousAssignee + "' to '" +
                newAssignee + "'.");
    }
}

It is installed in BPMN like this:

<flowable:taskListener event="assignment" class="x.x.x.flowable.engine.delegate.AssigneeOverrideTaskDelegate"></flowable:taskListener>

Additional context Tested in Flowable v6.7.2 and v6.5.0

verheyenkoen avatar Feb 01 '22 14:02 verheyenkoen