Task Complete Listener is not executed

Hi,
I have created a process which has one service task and one user task in same order.
A user task is configured with 2 task listeners via delegateExpression on create and complete events. The create task listener updates various variables such as assignee , task name etc. The create task listener also updates the task definition key as shown below.

taskEntity.setTaskDefinitionKey(“somekey”);

The issue I am having is that: when the task is marked complete via the rest api then the complete task listener is not firing.
I have discovered that when I remove the code that updates the task definition key, the complete task listener is invoked as expected. I see no errors and execution if flawless. It is important for me to invoke complete task listener since it produces an event which are consumed by downstream business processes.

I can not omit the code which updates the taskDefinitionKey since this key is utilized by other applications.

I am curious why when I update a taskDefinitionKey in create listener then why task completed listener is not being invoked? Is it by design ? or is this a defect?

Hi @RAJKUMAR_MEENA
Welcome to the forum

Can you please upload your model so that i can take a look at it.
Also - why exactly are you using the method exactly?
taskEntity.setTaskDefinitionKey(“somekey”);

What are you trying to achieve with this?

Thanks @Niall, I hope you had a good weekend !!

This key is obtained by frontend from some other system on which i do not have control. This key is dynamic and comes from front end application. When same task is retrived by frontend to display. There are some other values displayed on UI based on this key.custom_task_process.bpmn (3.6 KB)

Edit : Uploaded bpmn file. I am using camunda version 7.9

Did any body face this issue earlier ? If anybody can help me , it will be great.