REST API - Query by Process Definition Key fails for Deleted Deployments

On Camunda 7.5, REST API queries for process instance and task history return no results when querying by Process Definition Key, when the associated deployment has been deleted (even though the Cascade parameter has not been set to TRUE.) However, when querying for the same records based on process instance ID, the records are returned.

These steps demonstrate the problem.

  1. Create a deployment: POST engine-rest/deployment/create
    The returned data is:
{
  "links": [
    {
      "method": "GET",
      "href": "http://dev-solutions.accusoft.com:8080/engine-rest/deployment/a37ccda8-d6a2-11e6-ac5c-0242ac120003",
      "rel": "self"
    }
  ],
  "id": "a37ccda8-d6a2-11e6-ac5c-0242ac120003",
  "name": "TestParallelEnds",
  "source": null,
  "deploymentTime": "2017-01-09T19:34:29",
  "tenantId": "sbb"
}
  1. Get the Process Definition: GET engine-rest/process-definition?deploymentId=a37ccda8-d6a2-11e6-ac5c-0242ac120003
    The returned data is:
[
  {
    "id": "ID_Process_ParallelEnds:1:a383364a-d6a2-11e6-ac5c-0242ac120003",
    "key": "ID_Process_ParallelEnds",
    "category": "http://bpmn.io/schema/bpmn",
    "description": "This workflow has parallel paths that end in two different end events. It is intended to be used for testing.",
    "name": "Parallel Ends",
    "version": 1,
    "resource": "parallel-ends.bpmn",
    "deploymentId": "a37ccda8-d6a2-11e6-ac5c-0242ac120003",
    "diagram": null,
    "suspended": false,
    "tenantId": "sbb",
    "versionTag": null
  }
]
  1. Start an instance of this deployment and run it to conclusion.

  2. Get the Instance History (query with processDefinitionKey): GET engine-rest/history/process-instance?processDefinitionKey=ID_Process_ParallelEnds
    The returned data is:

[
  {
    "id": "eff7d046-d6a2-11e6-ac5c-0242ac120003",
    "businessKey": null,
    "processDefinitionId": "ID_Process_ParallelEnds:1:a383364a-d6a2-11e6-ac5c-0242ac120003",
    "processDefinitionKey": "ID_Process_ParallelEnds",
    "startTime": "2017-01-09T19:36:38",
    "endTime": "2017-01-09T19:37:40",
    "durationInMillis": 62626,
    "startUserId": "accusoft",
    "startActivityId": "StartEvent_1",
    "deleteReason": null,
    "superProcessInstanceId": null,
    "superCaseInstanceId": null,
    "caseInstanceId": null,
    "tenantId": "sbb"
  }
]
  1. Get History User Tasks (query with processDefinitionKey): ``GET `engine-rest/history/task?processDefinitionKey=ID_Process_ParallelEnds```
    The returned data is:
[
  {
    "id": "effc8b42-d6a2-11e6-ac5c-0242ac120003",
    "processDefinitionKey": "ID_Process_ParallelEnds",
    "processDefinitionId": "ID_Process_ParallelEnds:1:a383364a-d6a2-11e6-ac5c-0242ac120003",
    "processInstanceId": "eff7d046-d6a2-11e6-ac5c-0242ac120003",
    "executionId": "eff7f75e-d6a2-11e6-ac5c-0242ac120003",
    "caseDefinitionKey": null,
    "caseDefinitionId": null,
    "caseInstanceId": null,
    "caseExecutionId": null,
    "activityInstanceId": "UserTask_0sgpakl:eff7f75f-d6a2-11e6-ac5c-0242ac120003",
    "name": "Task A",
    "description": null,
    "deleteReason": "completed",
    "owner": null,
    "assignee": "accusoft",
    "startTime": "2017-01-09T19:36:38",
    "endTime": "2017-01-09T19:37:13",
    "duration": 35647,
    "taskDefinitionKey": "UserTask_0sgpakl",
    "priority": 50,
    "due": null,
    "parentTaskId": null,
    "followUp": null,
    "tenantId": "sbb"
  }, ...
  1. Delete the deployment: DEL engine-rest/deployment/a37ccda8-d6a2-11e6-ac5c-0242ac120003

  2. Get the Instance History (query with processDefinitionKey): GET engine-rest/history/process-instance?processDefinitionKey=ID_Process_ParallelEnds
    The returned data is an empty array.

  3. Get History User Tasks (query with processDefinitionKey): GET engine-rest/history/task?processDefinitionKey=ID_Process_ParallelEnds
    The returned data is an empty array.

  4. Get the Instance History (query for the specific instance): GET engine-rest/history/process-instance/eff7d046-d6a2-11e6-ac5c-0242ac120003
    The returned data is:

{
  "id": "eff7d046-d6a2-11e6-ac5c-0242ac120003",
  "businessKey": null,
  "processDefinitionId": "ID_Process_ParallelEnds:1:a383364a-d6a2-11e6-ac5c-0242ac120003",
  "processDefinitionKey": "ID_Process_ParallelEnds",
  "startTime": "2017-01-09T19:36:38",
  "endTime": "2017-01-09T19:37:40",
  "durationInMillis": 62626,
  "startUserId": "accusoft",
  "startActivityId": "StartEvent_1",
  "deleteReason": null,
  "superProcessInstanceId": null,
  "superCaseInstanceId": null,
  "caseInstanceId": null,
  "tenantId": "sbb"
}
  1. Get the Task History(query for the specific process instance): GET engine-rest/history/task?processInstanceId=eff7d046-d6a2-11e6-ac5c-0242ac120003
    The returned data is:
[
  {
    "id": "effc8b42-d6a2-11e6-ac5c-0242ac120003",
    "processDefinitionKey": "ID_Process_ParallelEnds",
    "processDefinitionId": "ID_Process_ParallelEnds:1:a383364a-d6a2-11e6-ac5c-0242ac120003",
    "processInstanceId": "eff7d046-d6a2-11e6-ac5c-0242ac120003",
    "executionId": "eff7f75e-d6a2-11e6-ac5c-0242ac120003",
    "caseDefinitionKey": null,
    "caseDefinitionId": null,
    "caseInstanceId": null,
    "caseExecutionId": null,
    "activityInstanceId": "UserTask_0sgpakl:eff7f75f-d6a2-11e6-ac5c-0242ac120003",
    "name": "Task A",
    "description": null,
    "deleteReason": "completed",
    "owner": null,
    "assignee": "accusoft",
    "startTime": "2017-01-09T19:36:38",
    "endTime": "2017-01-09T19:37:13",
    "duration": 35647,
    "taskDefinitionKey": "UserTask_0sgpakl",
    "priority": 50,
    "due": null,
    "parentTaskId": null,
    "followUp": null,
    "tenantId": "sbb"
  }, ...

So we see that the history data is still present. As expected, it was not deleted when the deployment was deleted. However, we can not retrieve this data by querying based on the Process Definition ID. This makes it inconvenient to retrieve the history data.

Is this lack of functionality by design or is it a defect? It seems to me that since the processDefinitionKey fields of the historic data are populated, we should be able to query based on the processDefinitionKey, even if the associated deployment has been deleted.

Hi @Stephen_Bucholtz,

Thank you for your detailed description.

The problem is that the HistoricProcessInstanceQuery does a left join to the process definition table 1. That joined table is used to compare the process definition key whether the passed process definition key matches it or not 2.
So, when you delete the deployment the corresponding stored process definitions are also deleted. As a consequence, the historic process instance cannot be found, because there is no process definition to join to that historic process instance row.

I agree with you that it feels weird, so feel free to create bug issue 3.

Cheers,
Roman

Created this bug report in Jira: https://app.camunda.com/jira/browse/CAM-7261

1 Like

As mentioned above, a bug report was created for this issue in January of this year. It looks like no action has been taken regarding this bug. Are there any plans to address this issue? We need to be able to query the workflow instance history by process definition key for instances associated with deleted deployments.

Also, I have just discovered that the same problem seems to exist for:
GET /engine-rest/history/task?processDefinitionKey=x

For a deleted deployment, this returns no tasks. However, issuing the GET with a query parameter of “tenantIdIn” returns tasks for the deleted deployment.

Hi @Stephen_Bucholtz,

We put this ticket in our backlog and after some prioritization it will be implemented, but we are not able to give an estimation when this issue will be fixed. If you need a commitment, I recommend you to become a enterprise customer and to raise a support ticket. However, you are always free to submit a pull request to fix this bug in order to speed things up. In 1 you will find the difference between enterprise and community edition.

Cheers,
Roman