Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not delete candidate user defined in BPMN with task's creation listener #4846

Open
tonny1983 opened this issue Dec 11, 2024 · 2 comments
Assignees
Labels
type:bug Issues that describe a user-facing bug in the project.

Comments

@tonny1983
Copy link

tonny1983 commented Dec 11, 2024

Environment

Camunda BPM Engine v7.22.0

Description

Candidate uers which is defined in BPMN model can not be removed in its task's creation listener with TaskService#deleteCandidate method.

Steps to reproduce

  1. There is a user task with candidate user abcdefg:
<bpmn:userTask id="UserActivity1" camunda:candidateUsers="abcdefg">
  1. The following js code is in its creation listener as follows:
var taskService = task.getProcessEngineServices().getTaskService();
taskService.addCandidateUser(task.getId(), "abc");
taskService.deleteCandidateUser(task.getId(), "abcdefg");
taskService.deleteCandidateUser(task.getId(), "abc");
  1. Start and test the process instance with camunda-bpm-assert

Observed Behavior

Both taskService().createTaskQuery().taskCandidateUser("abcdefg").count() and taskService().createTaskQuery().taskCandidateUser("abc").count() returns value of 1.

Expected behavior (Required on creation)

There should be no tasks the candidate user of which is "abcdefg" or "abc".

Root Cause

I'm not sure whether the problem related to the IdentityLinkManager#findIdentityLinkByProcessDefinitionUserAndGroup method which calls the selectIdentityLinkByTaskUserGroupAndType. In the method, it getDbEntityManager method to excute the sql.
As the INSERT sql of IdentityLinkEntity is obviously behind of this SELECT sql (shows in the following log), there are really no such a DB entity in the SQL transaction. However, the entity should exist in the persistence cache and could be retrieved.

Solution Ideas

Try to retrieve the IdentityLinkEntity from persistence cache first ???

Hints

Here is the detail console log about the process

16:55:51.161 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13005 Starting command -------------------- AddUserIdentityLinkCmd ----------------------
16:55:51.161 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13010 reusing existing command context
16:55:51.161 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13006 Finishing command -------------------- AddUserIdentityLinkCmd ----------------------
16:55:51.162 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13005 Starting command -------------------- DeleteUserIdentityLinkCmd ----------------------
16:55:51.162 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13010 reusing existing command context
16:55:51.162 [main] DEBUG o.c.b.e.i.p.e.I.selectIdentityLinkByTaskUserGroupAndType - ==>  Preparing: select * from ACT_RU_IDENTITYLINK where TASK_ID_ = ? and USER_ID_ = ? and TYPE_ = ?
16:55:51.163 [main] DEBUG o.c.b.e.i.p.e.I.selectIdentityLinkByTaskUserGroupAndType - ==> Parameters: 9(String), abcdefg(String), candidate(String)
16:55:51.163 [main] DEBUG o.c.b.e.i.p.e.I.selectIdentityLinkByTaskUserGroupAndType - <==      Total: 0
16:55:51.163 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13006 Finishing command -------------------- DeleteUserIdentityLinkCmd ----------------------
16:55:51.163 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13005 Starting command -------------------- DeleteUserIdentityLinkCmd ----------------------
16:55:51.163 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13010 reusing existing command context
16:55:51.163 [main] DEBUG o.c.b.e.i.p.e.I.selectIdentityLinkByTaskUserGroupAndType - ==>  Preparing: select * from ACT_RU_IDENTITYLINK where TASK_ID_ = ? and USER_ID_ = ? and TYPE_ = ?
16:55:51.163 [main] DEBUG o.c.b.e.i.p.e.I.selectIdentityLinkByTaskUserGroupAndType - ==> Parameters: 9(String), abc(String), candidate(String)
16:55:51.163 [main] DEBUG o.c.b.e.i.p.e.I.selectIdentityLinkByTaskUserGroupAndType - <==      Total: 0
16:55:51.163 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13006 Finishing command -------------------- DeleteUserIdentityLinkCmd ----------------------
16:55:51.166 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13011 closing existing command context
16:55:51.166 [main] DEBUG org.camunda.bpm.engine.persistence - ENGINE-03006 Cache state after flush: [
  PERSISTENT HistoricVariableInstanceEntity[12]
  PERSISTENT HistoricVariableInstanceEntity[7]
  PERSISTENT HistoricIdentityLinkLogEventEntity[11]
  PERSISTENT HistoricIdentityLinkLogEventEntity[15]
  PERSISTENT HistoricActivityInstanceEventEntity[UserActivity1:6]
  PERSISTENT HistoricActivityInstanceEventEntity[StartEvent_1:5]
  PERSISTENT TaskEntity[9]
  PERSISTENT ExecutionEntity[4]
  PERSISTENT HistoricTaskInstanceEventEntity[9]
  PERSISTENT VariableInstanceEntity[12]
  PERSISTENT VariableInstanceEntity[7]
  PERSISTENT HistoricVariableUpdateEventEntity[13]
  PERSISTENT HistoricVariableUpdateEventEntity[8]
  PERSISTENT IdentityLinkEntity[14]
  PERSISTENT IdentityLinkEntity[10]
  PERSISTENT ProcessDefinitionEntity[TwoUserTaskProcess:1:3]
  PERSISTENT HistoricProcessInstanceEventEntity[4]
]
16:55:51.167 [main] DEBUG org.camunda.bpm.engine.persistence - ENGINE-03008 Flush Summary: [
  INSERT HistoricVariableInstanceEntity[12]
  INSERT HistoricVariableInstanceEntity[7]
  INSERT HistoricVariableUpdateEventEntity[13]
  INSERT HistoricVariableUpdateEventEntity[8]
  INSERT HistoricTaskInstanceEventEntity[9]
  INSERT HistoricProcessInstanceEventEntity[4]
  INSERT HistoricIdentityLinkLogEventEntity[11]
  INSERT HistoricIdentityLinkLogEventEntity[15]
  INSERT HistoricActivityInstanceEventEntity[StartEvent_1:5]
  INSERT HistoricActivityInstanceEventEntity[UserActivity1:6]
  INSERT ExecutionEntity[4]
  INSERT TaskEntity[9]
  INSERT VariableInstanceEntity[12]
  INSERT VariableInstanceEntity[7]
  INSERT IdentityLinkEntity[10]
  INSERT IdentityLinkEntity[14]
]
16:55:51.167 [main] DEBUG org.camunda.bpm.engine.persistence - ENGINE-03009 SQL operation: 'INSERT'; Entity: 'HistoricVariableInstanceEntity[id=12]'
16:55:51.167 [main] DEBUG o.c.b.e.i.p.e.H.insertHistoricVariableInstance - ==>  Preparing: insert into ACT_HI_VARINST ( ID_, PROC_DEF_KEY_, PROC_DEF_ID_, ROOT_PROC_INST_ID_, PROC_INST_ID_, EXECUTION_ID_, ACT_INST_ID_, TENANT_ID_, CASE_DEF_KEY_, CASE_DEF_ID_, CASE_INST_ID_, CASE_EXECUTION_ID_, TASK_ID_, NAME_, REV_, VAR_TYPE_, CREATE_TIME_, REMOVAL_TIME_, BYTEARRAY_ID_, DOUBLE_, LONG_, TEXT_, TEXT2_, STATE_ ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
16:55:51.167 [main] DEBUG o.c.b.e.i.p.e.H.insertHistoricVariableInstance - ==> Parameters: 12(String), TwoUserTaskProcess(String), TwoUserTaskProcess:1:3(String), 4(String), 4(String), 4(String), UserActivity1:6(String), null, null, null, null, null, 9(String), task-start(String), 0(Integer), string(String), 2024-12-11 16:55:51.156(Timestamp), null, null, null, null, 1(String), null, CREATED(String)
16:55:51.167 [main] DEBUG org.camunda.bpm.engine.persistence - ENGINE-03009 SQL operation: 'INSERT'; Entity: 'HistoricVariableInstanceEntity[id=7]'
16:55:51.167 [main] DEBUG o.c.b.e.i.p.e.H.insertHistoricVariableInstance - ==> Parameters: 7(String), TwoUserTaskProcess(String), TwoUserTaskProcess:1:3(String), 4(String), 4(String), 4(String), 4(String), null, null, null, null, null, null, execution-start(String), 0(Integer), string(String), 2024-12-11 16:55:51.131(Timestamp), null, null, null, null, 1(String), null, CREATED(String)
16:55:51.168 [main] DEBUG org.camunda.bpm.engine.persistence - ENGINE-03009 SQL operation: 'INSERT'; Entity: 'HistoricVariableUpdateEventEntity[id=13]'
16:55:51.168 [main] DEBUG o.c.b.e.i.p.e.H.insertHistoricVariableUpdateEvent - ==>  Preparing: insert into ACT_HI_DETAIL ( ID_, TYPE_, PROC_DEF_KEY_, PROC_DEF_ID_, ROOT_PROC_INST_ID_, PROC_INST_ID_, EXECUTION_ID_, ACT_INST_ID_, CASE_DEF_KEY_, CASE_DEF_ID_, CASE_INST_ID_, CASE_EXECUTION_ID_, TASK_ID_, NAME_, REV_, VAR_INST_ID_, VAR_TYPE_, TIME_, BYTEARRAY_ID_, DOUBLE_, LONG_, TEXT_, TEXT2_, SEQUENCE_COUNTER_, TENANT_ID_, OPERATION_ID_, REMOVAL_TIME_, INITIAL_ ) values ( ?, 'VariableUpdate', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
16:55:51.169 [main] DEBUG o.c.b.e.i.p.e.H.insertHistoricVariableUpdateEvent - ==> Parameters: 13(String), TwoUserTaskProcess(String), TwoUserTaskProcess:1:3(String), 4(String), 4(String), 4(String), UserActivity1:6(String), null, null, null, null, 9(String), task-start(String), 0(Integer), 12(String), string(String), 2024-12-11 16:55:51.156(Timestamp), null, null, null, 1(String), null, 1(Long), null, null, null, false(Boolean)
16:55:51.169 [main] DEBUG org.camunda.bpm.engine.persistence - ENGINE-03009 SQL operation: 'INSERT'; Entity: 'HistoricVariableUpdateEventEntity[id=8]'
16:55:51.169 [main] DEBUG o.c.b.e.i.p.e.H.insertHistoricVariableUpdateEvent - ==> Parameters: 8(String), TwoUserTaskProcess(String), TwoUserTaskProcess:1:3(String), 4(String), 4(String), 4(String), UserActivity1:6(String), null, null, null, null, null, execution-start(String), 0(Integer), 7(String), string(String), 2024-12-11 16:55:51.131(Timestamp), null, null, null, 1(String), null, 1(Long), null, null, null, false(Boolean)
16:55:51.169 [main] DEBUG org.camunda.bpm.engine.persistence - ENGINE-03009 SQL operation: 'INSERT'; Entity: 'HistoricTaskInstanceEventEntity[id=9]'
16:55:51.169 [main] DEBUG o.c.b.e.i.p.e.H.insertHistoricTaskInstanceEvent - ==>  Preparing: insert into ACT_HI_TASKINST ( ID_, PROC_DEF_KEY_, PROC_DEF_ID_, ROOT_PROC_INST_ID_, PROC_INST_ID_, EXECUTION_ID_, CASE_DEF_KEY_, CASE_DEF_ID_, CASE_INST_ID_, CASE_EXECUTION_ID_, ACT_INST_ID_, NAME_, PARENT_TASK_ID_, DESCRIPTION_, OWNER_, ASSIGNEE_, START_TIME_, END_TIME_, DURATION_, DELETE_REASON_, TASK_DEF_KEY_, PRIORITY_, DUE_DATE_, FOLLOW_UP_DATE_, TENANT_ID_, REMOVAL_TIME_ ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
16:55:51.170 [main] DEBUG o.c.b.e.i.p.e.H.insertHistoricTaskInstanceEvent - ==> Parameters: 9(String), TwoUserTaskProcess(String), TwoUserTaskProcess:1:3(String), 4(String), 4(String), 4(String), null, null, null, null, UserActivity1:6(String), null, null, null, null, null, 2024-12-11 16:55:51.138(Timestamp), null, null, null, UserActivity1(String), 50(Integer), null, null, null, null
16:55:51.170 [main] DEBUG org.camunda.bpm.engine.persistence - ENGINE-03009 SQL operation: 'INSERT'; Entity: 'HistoricProcessInstanceEventEntity[id=4]'
16:55:51.170 [main] DEBUG o.c.b.e.i.p.e.H.insertHistoricProcessInstanceEvent - ==>  Preparing: insert into ACT_HI_PROCINST ( ID_, PROC_INST_ID_, BUSINESS_KEY_, PROC_DEF_KEY_, PROC_DEF_ID_, START_TIME_, END_TIME_, REMOVAL_TIME_, DURATION_, START_USER_ID_, START_ACT_ID_, END_ACT_ID_, SUPER_PROCESS_INSTANCE_ID_, ROOT_PROC_INST_ID_, SUPER_CASE_INSTANCE_ID_, CASE_INST_ID_, DELETE_REASON_, TENANT_ID_, STATE_ ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
16:55:51.170 [main] DEBUG o.c.b.e.i.p.e.H.insertHistoricProcessInstanceEvent - ==> Parameters: 4(String), 4(String), null, TwoUserTaskProcess(String), TwoUserTaskProcess:1:3(String), 2024-12-11 16:55:50.702(Timestamp), null, null, null, null, StartEvent_1(String), null, null, 4(String), null, null, null, null, ACTIVE(String)
16:55:51.170 [main] DEBUG org.camunda.bpm.engine.persistence - ENGINE-03009 SQL operation: 'INSERT'; Entity: 'HistoricIdentityLinkLogEventEntity[id=11]'
16:55:51.170 [main] DEBUG o.c.b.e.i.p.e.H.insertHistoricIdentityLinkLogEvent - ==>  Preparing: insert into ACT_HI_IDENTITYLINK ( ID_, TIMESTAMP_, TYPE_, USER_ID_, GROUP_ID_, TASK_ID_, ROOT_PROC_INST_ID_, PROC_DEF_ID_, OPERATION_TYPE_, ASSIGNER_ID_, PROC_DEF_KEY_, TENANT_ID_, REMOVAL_TIME_) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
16:55:51.171 [main] DEBUG o.c.b.e.i.p.e.H.insertHistoricIdentityLinkLogEvent - ==> Parameters: 11(String), 2024-12-11 16:55:51.137(Timestamp), candidate(String), abcdefg(String), null, 9(String), 4(String), TwoUserTaskProcess:1:3(String), add(String), null, TwoUserTaskProcess(String), null, null
16:55:51.171 [main] DEBUG org.camunda.bpm.engine.persistence - ENGINE-03009 SQL operation: 'INSERT'; Entity: 'HistoricIdentityLinkLogEventEntity[id=15]'
16:55:51.171 [main] DEBUG o.c.b.e.i.p.e.H.insertHistoricIdentityLinkLogEvent - ==> Parameters: 15(String), 2024-12-11 16:55:51.161(Timestamp), candidate(String), abc(String), null, 9(String), 4(String), TwoUserTaskProcess:1:3(String), add(String), null, TwoUserTaskProcess(String), null, null
16:55:51.171 [main] DEBUG org.camunda.bpm.engine.persistence - ENGINE-03009 SQL operation: 'INSERT'; Entity: 'HistoricActivityInstanceEventEntity[id=StartEvent_1:5]'
16:55:51.171 [main] DEBUG o.c.b.e.i.p.e.H.insertHistoricActivityInstanceEvent - ==>  Preparing: insert into ACT_HI_ACTINST ( ID_, PARENT_ACT_INST_ID_, PROC_DEF_KEY_, PROC_DEF_ID_, ROOT_PROC_INST_ID_, PROC_INST_ID_, EXECUTION_ID_, ACT_ID_, TASK_ID_, CALL_PROC_INST_ID_, CALL_CASE_INST_ID_, ACT_NAME_, ACT_TYPE_, ASSIGNEE_, START_TIME_, END_TIME_, DURATION_, ACT_INST_STATE_, SEQUENCE_COUNTER_, TENANT_ID_, REMOVAL_TIME_ ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
16:55:51.172 [main] DEBUG o.c.b.e.i.p.e.H.insertHistoricActivityInstanceEvent - ==> Parameters: StartEvent_1:5(String), 4(String), TwoUserTaskProcess(String), TwoUserTaskProcess:1:3(String), 4(String), 4(String), 4(String), StartEvent_1(String), null, null, null, null, startEvent(String), null, 2024-12-11 16:55:50.708(Timestamp), 2024-12-11 16:55:50.71(Timestamp), 2(Long), 4(Integer), 1(Long), null, null
16:55:51.172 [main] DEBUG org.camunda.bpm.engine.persistence - ENGINE-03009 SQL operation: 'INSERT'; Entity: 'HistoricActivityInstanceEventEntity[id=UserActivity1:6]'
16:55:51.172 [main] DEBUG o.c.b.e.i.p.e.H.insertHistoricActivityInstanceEvent - ==> Parameters: UserActivity1:6(String), 4(String), TwoUserTaskProcess(String), TwoUserTaskProcess:1:3(String), 4(String), 4(String), 4(String), UserActivity1(String), 9(String), null, null, null, userTask(String), null, 2024-12-11 16:55:50.711(Timestamp), null, null, 0(Integer), 3(Long), null, null
16:55:51.172 [main] DEBUG org.camunda.bpm.engine.persistence - ENGINE-03009 SQL operation: 'INSERT'; Entity: 'ExecutionEntity[id=4]'
16:55:51.172 [main] DEBUG o.c.b.e.i.p.e.E.insertExecution - ==>  Preparing: insert into ACT_RU_EXECUTION ( ID_, ROOT_PROC_INST_ID_, PROC_INST_ID_, BUSINESS_KEY_, PROC_DEF_ID_, ACT_ID_, ACT_INST_ID_, IS_ACTIVE_, IS_CONCURRENT_, IS_SCOPE_, IS_EVENT_SCOPE_, PARENT_ID_, SUPER_EXEC_, SUPER_CASE_EXEC_, CASE_INST_ID_, SUSPENSION_STATE_, CACHED_ENT_STATE_, SEQUENCE_COUNTER_, TENANT_ID_, REV_ ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1 )
16:55:51.173 [main] DEBUG o.c.b.e.i.p.e.E.insertExecution - ==> Parameters: 4(String), 4(String), 4(String), null, TwoUserTaskProcess:1:3(String), UserActivity1(String), UserActivity1:6(String), true(Boolean), false(Boolean), true(Boolean), false(Boolean), null, null, null, null, 1(Integer), 18(Integer), 3(Long), null
16:55:51.173 [main] DEBUG org.camunda.bpm.engine.persistence - ENGINE-03009 SQL operation: 'INSERT'; Entity: 'TaskEntity[id=9]'
16:55:51.173 [main] DEBUG o.c.b.e.i.p.e.TaskEntity.insertTask - ==>  Preparing: insert into ACT_RU_TASK ( ID_, NAME_, PARENT_TASK_ID_, DESCRIPTION_, PRIORITY_, CREATE_TIME_, LAST_UPDATED_, OWNER_, ASSIGNEE_, DELEGATION_, EXECUTION_ID_, PROC_INST_ID_, PROC_DEF_ID_, CASE_EXECUTION_ID_, CASE_INST_ID_, CASE_DEF_ID_, TASK_DEF_KEY_, DUE_DATE_, FOLLOW_UP_DATE_, SUSPENSION_STATE_, TENANT_ID_, REV_ ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1 )
16:55:51.173 [main] DEBUG o.c.b.e.i.p.e.TaskEntity.insertTask - ==> Parameters: 9(String), null, null, null, 50(Integer), 2024-12-11 16:55:51.136(Timestamp), 2024-12-11 16:55:51.163(Timestamp), null, null, null, 4(String), 4(String), TwoUserTaskProcess:1:3(String), null, null, null, UserActivity1(String), null, null, 1(Integer), null
16:55:51.173 [main] DEBUG org.camunda.bpm.engine.persistence - ENGINE-03009 SQL operation: 'INSERT'; Entity: 'VariableInstanceEntity[id=12]'
16:55:51.174 [main] DEBUG o.c.b.e.i.p.e.V.insertVariableInstance - ==>  Preparing: insert into ACT_RU_VARIABLE ( ID_, TYPE_, NAME_, PROC_DEF_ID_, PROC_INST_ID_, EXECUTION_ID_, CASE_INST_ID_, CASE_EXECUTION_ID_, TASK_ID_, BATCH_ID_, BYTEARRAY_ID_, DOUBLE_, LONG_, TEXT_, TEXT2_, VAR_SCOPE_, SEQUENCE_COUNTER_, IS_CONCURRENT_LOCAL_, TENANT_ID_, REV_ ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1 )
16:55:51.174 [main] DEBUG o.c.b.e.i.p.e.V.insertVariableInstance - ==> Parameters: 12(String), string(String), task-start(String), TwoUserTaskProcess:1:3(String), 4(String), 4(String), null, null, 9(String), null, null, null, null, 1(String), null, 9(String), 1(Long), false(Boolean), null
16:55:51.174 [main] DEBUG org.camunda.bpm.engine.persistence - ENGINE-03009 SQL operation: 'INSERT'; Entity: 'VariableInstanceEntity[id=7]'
16:55:51.174 [main] DEBUG o.c.b.e.i.p.e.V.insertVariableInstance - ==> Parameters: 7(String), string(String), execution-start(String), TwoUserTaskProcess:1:3(String), 4(String), 4(String), null, null, null, null, null, null, null, 1(String), null, 4(String), 1(Long), false(Boolean), null
16:55:51.174 [main] DEBUG org.camunda.bpm.engine.persistence - ENGINE-03009 SQL operation: 'INSERT'; Entity: 'IdentityLinkEntity[id=10]'
16:55:51.174 [main] DEBUG o.c.b.e.i.p.e.I.insertIdentityLink - ==>  Preparing: insert into ACT_RU_IDENTITYLINK (ID_, TYPE_, USER_ID_, GROUP_ID_, TASK_ID_, PROC_DEF_ID_, TENANT_ID_, REV_ ) values (?, ?, ?, ?, ?, ?, ?, 1 )
16:55:51.175 [main] DEBUG o.c.b.e.i.p.e.I.insertIdentityLink - ==> Parameters: 10(String), candidate(String), abcdefg(String), null, 9(String), null, null
16:55:51.175 [main] DEBUG org.camunda.bpm.engine.persistence - ENGINE-03009 SQL operation: 'INSERT'; Entity: 'IdentityLinkEntity[id=14]'
16:55:51.175 [main] DEBUG o.c.b.e.i.p.e.I.insertIdentityLink - ==> Parameters: 14(String), candidate(String), abc(String), null, 9(String), null, null
16:55:51.177 [main] DEBUG org.camunda.bpm.engine.tx - ENGINE-11002 firing event committing...
16:55:51.177 [main] DEBUG org.camunda.bpm.engine.tx - ENGINE-11002 committing the persistence session...
16:55:51.177 [main] DEBUG org.camunda.bpm.engine.tx - ENGINE-11002 firing event committed...
16:55:51.177 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13006 Finishing command -------------------- StartProcessInstanceCmd ----------------------

It seems that TaskService#deleteCandidate method firstly calls selectIdentityLinkByTaskUserGroupAndType SQL to check whether the IdentityLinkEntity exists or not. The AddUserIdentityLinkCmd and DeleteUserIdentityLinkCmd reuse the same existing command context as the log shows, the IdentityLinkEntity should exists not in fact the result of selectIdentityLinkByTaskUserGroupAndType is 0.

@tonny1983 tonny1983 added the type:bug Issues that describe a user-facing bug in the project. label Dec 11, 2024
@mboskamp
Copy link
Member

Hi @tonny1983,

Thanks for opening this issue. A workaround would be to create the candidate user in the listener and commit that to the database (e.g., have a transaction boundary). In another activity, delete the candidate user again.

The taskService (and other services) API works by interacting with the database. While it is technically possible to make it look for entities in the persistence cache, this would complicate the API calls a lot and would introduce other problems. For example, should the creation and deletion of the candidate user leave traces in the operation logs?

I don't think that this behavior is a bug and this issue should rather be a feature request. What do you think?
Without having investigated much now, I think changing the behavior you see is not feasible because of the high effort it would take and the relatively low impact. But most importantly, deleting newly created entities from an uncommited entity cache would raise more problems than it would solve.

Let me know what you think.

@tonny1983
Copy link
Author

Hi @mboskamp ,

Thanks a lot for your kind reply.

In fact, the issue is mainly based on the different behaviours between add/remove identity links and variables in the task listener.
When adding and removing variables in the create listener of tasks as follows:

task.setVariable("key1","value1");
task.removeVariable("key1");

var runtimeService = task.getProcessEngineServices().getRuntimeService();
runtimeService.setVariable(task.getProcessInstanceId(), "key2", "value2");
runtimeService.removeVariable(task.getProcessInstanceId(), "key2");

The removeVariable method properly works and the following assertion is true:

var variableCount = runtimeService().createVariableInstanceQuery().count();
Assertions.assertEquals(0, variableCount);

By comparing the behaviour of DeleteUserIdentityLinkCmd and RemoveExecutionVariablesCmd, it seems the only difference is that DeleteUserIdentityLinkCmd calls a DB query before delete it.

10:34:53.151 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13005 Starting command -------------------- AddUserIdentityLinkCmd ----------------------
10:34:53.151 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13010 reusing existing command context
10:34:53.154 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13006 Finishing command -------------------- AddUserIdentityLinkCmd ----------------------
10:34:53.154 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13005 Starting command -------------------- DeleteUserIdentityLinkCmd ----------------------
10:34:53.154 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13010 reusing existing command context
10:34:53.155 [main] DEBUG o.c.b.e.i.p.e.I.selectIdentityLinkByTaskUserGroupAndType - ==>  Preparing: select * from ACT_RU_IDENTITYLINK where TASK_ID_ = ? and USER_ID_ = ? and TYPE_ = ?
10:34:53.155 [main] DEBUG o.c.b.e.i.p.e.I.selectIdentityLinkByTaskUserGroupAndType - ==> Parameters: 7(String), abc(String), candidate(String)
10:34:53.155 [main] DEBUG o.c.b.e.i.p.e.I.selectIdentityLinkByTaskUserGroupAndType - <==      Total: 0
10:34:53.155 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13006 Finishing command -------------------- DeleteUserIdentityLinkCmd ----------------------
10:34:53.158 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13005 Starting command -------------------- SetExecutionVariablesCmd ----------------------
10:34:53.158 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13010 reusing existing command context
10:34:53.159 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13006 Finishing command -------------------- SetExecutionVariablesCmd ----------------------
10:34:53.159 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13005 Starting command -------------------- RemoveExecutionVariablesCmd ----------------------
10:34:53.159 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13010 reusing existing command context
10:34:53.160 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13006 Finishing command -------------------- RemoveExecutionVariablesCmd --------------------

With full respect for different opinions, I'm afraid that this difference contains at least a bug there and I chose the behaviour of deleting candidate user because in mu opinion that the query before delete is unnecessory (deleting a non-existent entity in db seems no harmful effects).

Thank you for your time and I'm awaiting your futher response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Issues that describe a user-facing bug in the project.
Projects
None yet
Development

No branches or pull requests

2 participants