AnsweredAssumed Answered

5.11 breaks creating task & adding group -NeedsActiveTaskCmd

Question asked by sangv on Feb 7, 2013
Latest reply on Feb 13, 2013 by jbarrez
I recently upgraded to 5.11 and find that my working code is now broken.

For a specific usecase, we create a task on the fly from a service task and add a candidate group to it.

public void execute(DelegateExecution delegateExecution) throws Exception {
TaskEntity task = (TaskEntity) taskService.newTask();

        for(String group: groups){
             addCandidateGroup(task.getId(), group);

But since the upgrade to 5.11, it seems that the NeedsActiveTaskCmd gets invoked which checks against the task entity manager with the task id before allowing the candidate group to be added. However since the saveTask call has not been committed, the task does not exist in the database leading to this exception stack trace.

org.activiti.engine.ActivitiException: Cannot find task with id 196
     at org.activiti.engine.impl.cmd.NeedsActiveTaskCmd.execute(
     at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(
     at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(
     at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(
     at org.activiti.spring.SpringTransactionInterceptor.execute(
     at org.activiti.engine.impl.interceptor.LogInterceptor.execute(
     at org.activiti.engine.impl.TaskServiceImpl.addCandidateGroup(

Since, I am saving the task and adding the candidate group in the same service task (running under the context of activiti's transaction),  the task never gets persisted (even without the candidate group link). So, basically the interceptor now leads to my tasks not being persisted at all.

Basically, my questions is
i) Was this the expected behavior? It seems not to me because this will force me to potentially use 2 async service tasks or start managing multiple transactions within the service task. There was a similar issue reported with creating attachments which seems to have been caused by the same command being invoked. -