Closed Workflow Executions Request builder doesn't allow both status filter and type filter

I’m trying to get a list of Closed workflows that have failed, of a specific type of workflow, with a certain time filter.

This is what I have:

ListClosedWorkflowExecutionsRequest closedWorkflowExecutionsRequest = ListClosedWorkflowExecutionsRequest
                .newBuilder()
                .setNamespace(namespace)
                .setStartTimeFilter(
                        StartTimeFilter
                                .newBuilder()
                                .setEarliestTime(
                                        Timestamps
                                                .fromMillis(System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(startTimeMinutes))
                                )
                                .setLatestTime(
                                        Timestamps
                                                .fromMillis(System.currentTimeMillis())
                                )
                                .build()
                )
                //status filter is empty for some reason
                .setStatusFilter(
                        StatusFilter
                                .newBuilder()
                                .setStatus(WORKFLOW_EXECUTION_STATUS_FAILED)
                                .build()
                )
                .setTypeFilter(
                        WorkflowTypeFilter
                                .newBuilder()
                                .setName(workflowType)
                                .build()
                )
                .build();

        System.out.println(
                "Request type filter: " + closedWorkflowExecutionsRequest.getTypeFilter() + "\n" +
                "Request time filter: " + closedWorkflowExecutionsRequest.getStartTimeFilter() + "\n" +
                "Request status filter: " + closedWorkflowExecutionsRequest.getStatusFilter() + "\n" +
                "Request namespace filter: " + closedWorkflowExecutionsRequest.getNamespace()
        );

Now, the issue here is that the status filter is not being applied. If we check the output of the system out line:

Request type filter: name: "MyWorkflow"

Request time filter: earliest_time {
  seconds: 1692265753
  nanos: 549000000
}
latest_time {
  seconds: 1692524953
  nanos: 551000000
}

Request status filter: 
Request namespace filter: default
Found 118 workflows

Now the interesting thing is, if I call setTypeFilter() before setStatusFilter(), the type filter is now empty but the status filter isn’t.

Request type filter: 
Request time filter: earliest_time {
  seconds: 1692269939
  nanos: 39000000
}
latest_time {
  seconds: 1692529139
  nanos: 42000000
}

Request status filter: status: WORKFLOW_EXECUTION_STATUS_FAILED

Request namespace filter: default
Found 96 workflows

It seems that I can only have one of these filters applied at the same time, however this makes no sense as I can run this query by hand through the temporal UI and it works fine, so clearly there is no limitation on the gRPC server. Am I doing something wrong?

Hi there,

What you have observed is the expected behaviour based on the current API spec (oneof):

So only one of the filters (wf/run Ids), workflow type or status can be used to filter the workflow execution.

UI and CLI uses ListWorkflowExecutions instead which supports a more flexible query syntax.

Not sure if this example helps: https://github.com/temporalio/samples-java/blob/5fe9f2a5be88726e07023b946fd0724d7927e932/src/main/java/io/temporal/samples/listworkflows/Starter.java#L65-L69

Wow, that’s a bit disappointing.

Yeah this example helps, I can just construct the query as if I’m doing it by hand in the UI.

Thank you.

Also, we may end up deprecating these restrictive APIs: [Feature Request] Deprecate list workflow methods? · Issue #307 · temporalio/api · GitHub

I feel like I got caught in 4k :rofl:

I’ll look into the suggested endpoints in that Issue, thank you.