Skip to content

query() method implementation in WorkflowStubImpl ignores RunId #602

Open
@justinkov

Description

@justinkov

At about line 429 of com.uber.cadence.internal.sync.WorkflowStubImpl.java, the building of the QueryWorkflowParameters object doesn't set the run id if present:

QueryWorkflowParameters p = new QueryWorkflowParameters();
p.setInput(dataConverter.toData(args));
p.setQueryType(queryType);
p.setWorkflowId(execution.get().getWorkflowId());
p.setQueryRejectCondition(queryRejectCondition);

Adding something like the following fixed the problem for me:

if (execution.get().getRunId() != null) {
    p.setRunId(execution.get().getRunId());
}

Without this, the following sample code will always pull the latest run and ignore the the run id:

IWorkflowService cadenceService = new WorkflowServiceTChannel();
WorkflowClient client = WorkflowClient.newInstance(cadenceService, DOMAIN);
WorkflowStub workflow = client.newUntypedWorkflowStub(workflowId, Optional.of(runId), Optional.empty());
String result = workflow.query(queryType, String.class);

To see the problem, you would need to kick off multiple runs of a workflow that have the same workflow id. If the first run fails for some reason and the second one is successful, the sample code above will always only pull the successful run. If I add the suggested code above, I am able to successfully retrieve the failed run.

The only way then to retrieve the failed run is to use the WorkflowExecutionUtils class.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions